Reputation: 43
I am wondering if you can run Ant on a buildfile that would be located inside a JAR. The reason why I am interested in this is because I would like to include a "deploy" target in my buildfile that could be called after the jar has been moved to its destination. That "deploy" target would take care of extracting resources and other libraries required to run the program.
So, for instance, I would package up properties, images and external jars inside of my jar when building. The deployment process would then consist of moving the jar to the location it is meant to run in, and call ant <someOption> myjar.jar/build.xml deploy
or something like that.
Does that make sense?
Upvotes: 3
Views: 120
Reputation: 18459
Ant's build file parsing can be extended using ProjectHelper. Default one loads only files (source).
You could extend it to process an XML source, which can come from a jar (probably using getResourceAsStream(..))
[ Side note: You can run ant programmatically. No need to extract and then run command line - see Running ANT Programmatically Through Java ]
Upvotes: 1
Reputation: 4727
I think there isn't a way ant
can get a build file inside a jar.
For the method you described, you'll need to unzip build.xml
and pass it to ant. Since ant does not take stdin
as an argument to the buildfile, you'll need to store the buildfile then delete it:
$ unzip myjar.jar build.xml
$ ant deploy
$ rm build.xml
But is it necessary to the application running environment have ant installed only to extract these resources? Couldn't it be done inside your application? Or can't you distribute a zip file with you jar, library jars and images?
Or maybe creating an installer should be more appropriate: I\Pack or, if Windows only, NSIS.
Upvotes: 1