FAQ
Hello everybody:
I am trying to use Ant Task programmatically by invoking the API within my
Java code.

I get an exception, but everything appears to be fine to my eyes - I indeed
set all the compulsory attributes of the SignJar task. Probably somebody
else here has a good suggestion or the solution.

Thanks in advance!

Dan

----------------------------
My code is:

String sigFile = Paths.SIG_FILE_PATH;

SignJar sj = new SignJar();

sj.setAlias("myDep");
sj.setStorepass("aPassword");

sj.setJar(new File(fileName));
sj.setSigfile(sigFile);

sj.execute();

The exception I get is:

Exception in thread "main" java.lang.NullPointerException
at
org.apache.tools.ant.types.AbstractFileSet.setupDirectoryScanner(AbstractFileSet.java:477)
at
org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFileSet.java:442)
at org.apache.tools.ant.types.FileSet.iterator(FileSet.java:69)
at
org.apache.tools.ant.types.resources.Union.getCollection(Union.java:110)
at
org.apache.tools.ant.types.resources.Union.getCollection(Union.java:90)
at
org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.cacheCollection(BaseResourceCollectionContainer.java:250)
at
org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.iterator(BaseResourceCollectionContainer.java:126)
at org.apache.tools.ant.types.Path.iterator(Path.java:693)
at org.apache.tools.ant.taskdefs.SignJar.execute(SignJar.java:321)

Search Discussions

  • Mark Salter at Nov 5, 2008 at 7:47 pm

    Daniele Development-ML wrote:

    I am trying to use Ant Task programmatically by invoking the API within my
    Java code.
    You need a Project :-

    SignJar sj = new SignJar();
    sj.setProject(new Project());

    I surmised this by stepping through the code, but only 'blindly'.
    I guess all tasks need a project (it's presence is presumed), but I
    would hope this would be stated somewhere - I am going looking now.

    --
    Mark

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Morgan Kinne at Nov 5, 2008 at 8:04 pm
    try sj.perform()



    From:
    "Daniele Development-ML" <daniele.dml@googlemail.com>
    To:
    "Ant Users List" <user@ant.apache.org>
    Date:
    11/05/2008 12:17 PM
    Subject:
    Using Ant Tasks programmatically - SignJar Tasl



    Hello everybody:
    I am trying to use Ant Task programmatically by invoking the API within my
    Java code.

    I get an exception, but everything appears to be fine to my eyes - I
    indeed
    set all the compulsory attributes of the SignJar task. Probably somebody
    else here has a good suggestion or the solution.

    Thanks in advance!

    Dan

    ----------------------------
    My code is:

    String sigFile = Paths.SIG_FILE_PATH;

    SignJar sj = new SignJar();

    sj.setAlias("myDep");
    sj.setStorepass("aPassword");

    sj.setJar(new File(fileName));
    sj.setSigfile(sigFile);

    sj.execute();

    The exception I get is:

    Exception in thread "main" java.lang.NullPointerException
    at
    org.apache.tools.ant.types.AbstractFileSet.setupDirectoryScanner(AbstractFileSet.java:477)
    at
    org.apache.tools.ant.types.AbstractFileSet.getDirectoryScanner(AbstractFileSet.java:442)
    at org.apache.tools.ant.types.FileSet.iterator(FileSet.java:69)
    at
    org.apache.tools.ant.types.resources.Union.getCollection(Union.java:110)
    at
    org.apache.tools.ant.types.resources.Union.getCollection(Union.java:90)
    at
    org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.cacheCollection(BaseResourceCollectionContainer.java:250)
    at
    org.apache.tools.ant.types.resources.BaseResourceCollectionContainer.iterator(BaseResourceCollectionContainer.java:126)
    at org.apache.tools.ant.types.Path.iterator(Path.java:693)
    at org.apache.tools.ant.taskdefs.SignJar.execute(SignJar.java:321)
  • Mark Salter at Nov 5, 2008 at 9:11 pm

    Morgan Kinne wrote:
    try sj.perform()
    It looks to me like you will still need to set a sj.setProject(project).

    I can't find anything that states this requirement, sorry.

    --
    Mark

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Daniele Development-ML at Nov 6, 2008 at 10:21 am
    Thanks.
    I tried your suggestions, and the problem concerned that seems to be solved
    - thanks!

    Now, I get another exception, which seems somehow related to ant libraries -
    this is my understanding. I have included all the ant jars in my
    application. I post the exception and the new code - hoping in other
    suggestions.

    Thanks!

    Dan

    The new code is:

    Project project = new Project();
    Target target = new Target();
    SignJar sj = new SignJar();
    target.addTask(sj);

    project.addTarget("sign_jar", target);

    sj.setAlias("myDep");
    sj.setStorepass("myPrj");
    sj.setProject(project);

    sj.setJar(new File(fileName));
    sj.setSigfile(sigFile);

    project.executeTarget("sign_jar");

    Exception:

    Exception in thread "main" jarsigner returned: 1
    at
    org.apache.tools.ant.taskdefs.ExecTask.runExecute(ExecTask.java:636)
    at org.apache.tools.ant.taskdefs.ExecTask.runExec(ExecTask.java:662)
    at org.apache.tools.ant.taskdefs.ExecTask.execute(ExecTask.java:487)
    at
    org.apache.tools.ant.taskdefs.SignJar.signOneJar(SignJar.java:407)
    at org.apache.tools.ant.taskdefs.SignJar.execute(SignJar.java:336)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at
    org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:357)
    at org.apache.tools.ant.Target.performTasks(Target.java:385)
    at
    org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1306)



    On Wed, Nov 5, 2008 at 9:10 PM, Mark Salter wrote:

    Morgan Kinne wrote:
    try sj.perform()
    It looks to me like you will still need to set a sj.setProject(project).

    I can't find anything that states this requirement, sorry.

    --
    Mark

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Stefan Bodewig at Nov 6, 2008 at 10:29 am

    On Thu, 6 Nov 2008, Daniele Development-ML wrote:

    Now, I get another exception, which seems somehow related to ant
    libraries - this is my understanding.
    Not really.
    Exception in thread "main" jarsigner returned: 1 at
    means the native jarsigner executable invoked eby Ant xited with exit
    code 1, which means an error occured while running it. It also means
    that Ant was able to invoke jarsigner.

    If you were running the same task with the same attributes inside Ant,
    you should get the command line when running in verbose mode. You
    don't seem to have set up any loggers/listeners so it's hard to tell
    where your log messages end up now.

    Stefan

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Steve Loughran at Nov 6, 2008 at 12:50 pm

    Stefan Bodewig wrote:
    On Thu, 6 Nov 2008, Daniele Development-ML wrote:

    Now, I get another exception, which seems somehow related to ant
    libraries - this is my understanding.
    Not really.
    Exception in thread "main" jarsigner returned: 1 at
    means the native jarsigner executable invoked eby Ant xited with exit
    code 1, which means an error occured while running it. It also means
    that Ant was able to invoke jarsigner.

    If you were running the same task with the same attributes inside Ant,
    you should get the command line when running in verbose mode. You
    don't seem to have set up any loggers/listeners so it's hard to tell
    where your log messages end up now.
    Here's some example code to set up the logging in a project when
    embedding Ant

    http://antbook.cvs.sourceforge.net/viewvc/antbook/examples/sections/extending/ch18_extras/embed/src/org/antbook/embed/Embedded.java?revision=1.3&view=markup

    Some of that code is something we should really pull into Ant to make it
    easier; some EmbeddedProject you create to remove effort. What do you
    think, Stefan?

    --
    Steve Loughran http://www.1060.org/blogxter/publish/5
    Author: Ant in Action http://antbook.org/

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Stefan Bodewig at Nov 7, 2008 at 5:28 am

    On Thu, 06 Nov 2008, Steve Loughran wrote:

    Some of that code is something we should really pull into Ant to
    make it easier; some EmbeddedProject you create to remove
    effort. What do you think, Stefan?
    Sounds good. This might help projects like Gant or Lancet
    <http://groups.google.de/group/clojure/browse_thread/thread/7fc2ac972e9a39c9>
    as well.

    Stefan

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Steve Loughran at Nov 6, 2008 at 12:46 pm

    Mark Salter wrote:
    Morgan Kinne wrote:
    try sj.perform()
    It looks to me like you will still need to set a sj.setProject(project).

    I can't find anything that states this requirement, sorry.
    There's some coverage of it the Ant docs
    http://ant.apache.org/manual/antexternal.html

    as usual, contributions to improve this -more examples etc- are welcome.
    --
    Steve Loughran http://www.1060.org/blogxter/publish/5
    Author: Ant in Action http://antbook.org/

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Mark Salter at Nov 6, 2008 at 12:53 pm

    Steve Loughran wrote:
    There's some coverage of it the Ant docs
    http://ant.apache.org/manual/antexternal.html

    as usual, contributions to improve this -more examples etc- are welcome.
    Thanks Steve, certainly the advice given at the bottom of this page is
    probably most relevant to the OP:-

    "
    The question you are probably asking yourself at this point is: How
    would I know which classes and methods have to be called in order to set
    up a dummy Project and Target? The answer is: you don't. Ultimately, you
    have to be willing to get your feet wet and read the source code. The
    above example is merely designed to whet your appetite and get you
    started. Go for it!
    "

    --
    Mark

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Peter Reilly at Nov 6, 2008 at 1:19 pm
    Also be aware that the ant java code is not designed or created to be
    used as a library. Ant java code is written to read and execute ant xml scripts.

    Peter
    On Thu, Nov 6, 2008 at 12:53 PM, Mark Salter wrote:
    Steve Loughran wrote:
    There's some coverage of it the Ant docs
    http://ant.apache.org/manual/antexternal.html

    as usual, contributions to improve this -more examples etc- are welcome.
    Thanks Steve, certainly the advice given at the bottom of this page is
    probably most relevant to the OP:-

    "
    The question you are probably asking yourself at this point is: How
    would I know which classes and methods have to be called in order to set
    up a dummy Project and Target? The answer is: you don't. Ultimately, you
    have to be willing to get your feet wet and read the source code. The
    above example is merely designed to whet your appetite and get you
    started. Go for it!
    "

    --
    Mark

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
  • Daniele Development-ML at Nov 7, 2008 at 10:27 am
    Yes, Peter, I totally agree with you. However, I would expect that the XML
    elements and attributes are matched against some Java classes and calling
    them in the same order as does the Ant parser does, it would work. And
    actually it does with the above suggested statements.
    Of course, it depends on the way Ant it's implemented, but considering the
    team, I was sure they did a great job.

    Cheers,

    Dan


    On Thu, Nov 6, 2008 at 1:18 PM, Peter Reilly wrote:

    Also be aware that the ant java code is not designed or created to be
    used as a library. Ant java code is written to read and execute ant xml
    scripts.

    Peter
    On Thu, Nov 6, 2008 at 12:53 PM, Mark Salter wrote:
    Steve Loughran wrote:
    There's some coverage of it the Ant docs
    http://ant.apache.org/manual/antexternal.html

    as usual, contributions to improve this -more examples etc- are welcome.
    Thanks Steve, certainly the advice given at the bottom of this page is
    probably most relevant to the OP:-

    "
    The question you are probably asking yourself at this point is: How
    would I know which classes and methods have to be called in order to set
    up a dummy Project and Target? The answer is: you don't. Ultimately, you
    have to be willing to get your feet wet and read the source code. The
    above example is merely designed to whet your appetite and get you
    started. Go for it!
    "

    --
    Mark

    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org
    ---------------------------------------------------------------------
    To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
    For additional commands, e-mail: user-help@ant.apache.org

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupuser @
categoriesant
postedNov 5, '08 at 5:16p
activeNov 7, '08 at 10:27a
posts12
users6
websiteant.apache.org

People

Translate

site design / logo © 2017 Grokbase