如何建立与蚂蚁一个分发的JAR为Java项目有外部依赖的JAR [英] How to build a distributable jar with Ant for a java project having external jar dependencies
问题描述
我在Eclipse中类的Java项目 MainClass
具有封装主要方法:
I have a Java project in Eclipse with class MainClass
having main method in package :
com.nik.mypackage.
该项目还引用两个外部库,我在Eclipse中的 LIB
文件夹中复制,然后添加使用添加JAR 构建路径code>功能。该库是
one.jar
和 two.jar
The project also references two external libraries, which I copied in the lib
folder in Eclipse and then added to build path using ADD JAR
function. The libraries being one.jar
and two.jar
本库在 LIB
在eclipse文件夹,并添加到构建路径。
This library is in lib
folder in eclipse and added to the build path.
我要创建一个使用ant脚本的应用程序的可执行文件 JAR
。这样用户就可以访问我的使用命令的应用程序:
I want to create a executable JAR
of the application using ant script. So that user can access my application using command:
c:>java -jar MyProject-20111126.jar
我知道这直接导出一个Java应用程序可运行 JAR
的Eclipse插件。但我想学蚂蚁和构建过程人工手动要创建的build.xm。
I know about the Eclipse plugin which directly exports a java application as runnable JAR
. But I want to learn ant and the build process so manually want to create the build.xm.
推荐答案
您从您的build.xml两个选项。您可以不能解压缩的jar包,然后捆绑其内容编译为您的应用code。或者,你可以把文件系统中的jar包,并提供在MyProject的-2011126.jar文件的清单文件中类路径条目。
You have two options from your build.xml. You can either unjar the library jars and then bundle their contents with the code compiled for your application. Or, you can put the library jars on the filesystem and supply a ClassPath entry in the manifest file of the MyProject-2011126.jar file.
如果您设置的类路径在清单记住您提供的路径是相对于MyProject的-2011126.jar。
If you set the classpath in the manifest remember that the path you supply is relative to the MyProject-2011126.jar.
这篇关于如何建立与蚂蚁一个分发的JAR为Java项目有外部依赖的JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!