创建与蚂蚁一个可执行的JAR文件,其中包含build.xml文件 [英] creating an executable jar file with ant which includes the build.xml file

查看:522
本文介绍了创建与蚂蚁一个可执行的JAR文件,其中包含build.xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Ant构建应用程序,运行应用程序的main()方法,运行JUnit测试,并打包一个jar文件的一切(来源+ +建设+库build.xml文件)。这些类包括一个main()方法的切入点亚军类。

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.

目标却是要inlcude使用的所有的库,例如的junit.jar和ant的build.xml文件本身。

The objective however is to inlcude all libraries used, like junit.jar, and the ant build.xml itself.

我想知道是否有可执行的JAR文件的方式,来运行Ant构建文件itslef的选定目标,而不只是在main()方法。很显然,我并不需要再次运行编译目标,但只有main()方法(在我的运行目标Java元素)和JUnit的目标。这可能吗?

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!

推荐答案

可执行的JAR是不是你认为它是。它可以让你收拾所有的的课一起上(你可以添加源一样好,虽然我看到那个小点)和JAR清单利用Main-Class属性声明一个主类。详情这里

"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.

您可以然后启动通过 Java的罐子my.jar 命令行罐子这将调用的main()您指定的类的方法。您还可以指定的类路径通过在manifest文件中可以指向您的应用程序所需的其他jar文件的Class-Path 属性。这不等于那些罐子你的JAR内存档;其实如果你这样做,JVM将无法从这些瓶子装载类,除非你采取特殊的precautions,写一个定制的ClassLoader。

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.

这篇关于创建与蚂蚁一个可执行的JAR文件,其中包含build.xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆