creating an executable jar file with ant which includes the build.xml file
I am trying to use ant to build an application, run the application's main() method, run junit tests, and package everything in a jar file (source+build+libraries+build.xml). The classes include a runner class with a main() method entry point.
The objective however is to inlcude all libraries used, like junit.jar, and the ant build.xml itself.
I was wondering if there is a way for the executable jar file, to run selected targets of the ant build file itslef, instead of just the main() method. Obviously I wouldn't need to run the compile targets again, but only the main() method (the java element in my run target) and the junit target. Is that possible?
Many thanks in advance for the insight!
"Executable jar" is not what you think it is. It allows you pack all your classes together (you can add source to it as well though I see little point in that) and declare a main class using Main-Class attribute in the jar manifest. Details are here.
You can then launch that jar using " java -jar my.jar
" command line which would invoke main()
method of the class you've specified. You can also specify classpath via Class-Path
attribute in the manifest file that can point to other jars needed by your application. That DOES NOT MEAN those jars are archived within your jar; in fact if you were to do that, JVM won't be able to load classes from those jars unless you were to take special precautions and write a custom classloader.
上一篇: 任务,我应该在哪里放置新的类文件?