简体   繁体   中英

Run ant script from jar file

Is it possible to run an ant script from within a jar file?

At the moment, I've got a build.xml which calls some java code which is in a jar file. It then does some further ant processing.

When I export the jar file from Eclipse, I can choose to add the build.xml file to the jar, so I'm wondering whether I could run the ant script directly from the jar somehow so that I only have to give people the jar file, not the ant script as well.

The answer is cyclic. Are you trying to add the build.xml to execute A.jar into A.jar itself? If so, you want to execute the jar with the parameters mentioned in the build.xml. If this is the case, you might as well write a main method which runs with those specific set of parameters.

In any case, there should always be a way to run your jar with some parameters which can be accomplished without the build.xml.

If you really need to do this via ant, use this Starting a process in Java?

Update:

See this link in stackoverflow. -> Run ant from Java

I have not tried this personally but this is one way to go provided you take care of the cyclic nature of your problem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM