ANT教程之九 Ant创建JAR文件
2015-11-07 16:35
316 查看
编译Java源文件后的下一个合乎逻辑的步骤,是建立在Java归档,JAR文件。创建JAR文件与Ant用jar任务很容易。以下展示的是jar任务的常用属性
继续我们的Hello World传真应用程序项目,让我们添加一个新的目标,产生的jar文件。但在此之前,让我们考虑一下jar任务:
在这个例子中,web.dir属性指向的网页源文件的路径。在我们的例子中,这是其中的util.jar将被放置。
在这个例子中,build.dir属性指向build文件夹在哪里可以找到 util.jar的类文件。
在这个例子中,我们创建了一个名为util.jar使用的类从faxapp.util一个jar文件。*包。然而,我们不包括用名称测试结束课程。输出的jar文件会发生在webapp的lib文件夹。
如果我们想使util.jar一个可执行JAR文件,我们需要添加清单与主Classmeta属性。
因此,上面的例子将被更新为:
要执行jar任务,一个目标里面把它包(最常见,构建或包的目标,并运行它们。
在这个文件运行Ant会为我们创建util.jar文件
下面的结果是运行Ant文件的结果:
现在的util.jar文件放置在输出文件夹。
属性 | 描述 |
---|---|
basedir | The base directory for the output JAR file. By default, this is set to the base directory of the project. |
compress | Advises ant to compress the file as it creates the JAR file. |
keepcompression | While the compress attribute is applicable to the individual files, thekeepcompression attribute does the same thing, but it applies to the entire archive. |
destfile | The name of the output JAR file |
duplicate | Advises Ant on what to do when duplicate files are found. You could add, preserve or fail the duplicate files. |
excludes | Advises Ant to not include these comma separated list of files in the package. |
excludesfile | Same as above, except the exclude files are specified using a pattern. |
inlcudes | Inverse of excludes |
includesfile | Inverse of excludesfile. |
update | Advises ant to overwrite files in the already built JAR file. |
<jar destfile="${web.dir}/lib/util.jar" basedir="${build.dir}/classes" includes="faxapp/util/**" excludes="**/Test.class" />
在这个例子中,web.dir属性指向的网页源文件的路径。在我们的例子中,这是其中的util.jar将被放置。
在这个例子中,build.dir属性指向build文件夹在哪里可以找到 util.jar的类文件。
在这个例子中,我们创建了一个名为util.jar使用的类从faxapp.util一个jar文件。*包。然而,我们不包括用名称测试结束课程。输出的jar文件会发生在webapp的lib文件夹。
如果我们想使util.jar一个可执行JAR文件,我们需要添加清单与主Classmeta属性。
因此,上面的例子将被更新为:
<jar destfile="${web.dir}/lib/util.jar" basedir="${build.dir}/classes" includes="faxapp/util/**" excludes="**/Test.class"> <manifest> <attribute name="Main-Class" value="com.yiibai.util.FaxUtil"/> </manifest> </jar>
要执行jar任务,一个目标里面把它包(最常见,构建或包的目标,并运行它们。
<target name="build-jar">
<jar destfile="${web.dir}/lib/util.jar" basedir="${build.dir}/classes" includes="faxapp/util/**" excludes="**/Test.class"> <manifest> <attribute name="Main-Class" value="com.yiibai.util.FaxUtil"/> </manifest> </jar>
</target>
在这个文件运行Ant会为我们创建util.jar文件
下面的结果是运行Ant文件的结果:
C:>ant build-jar Buildfile: C:uild.xml BUILD SUCCESSFUL Total time: 1.3 seconds
现在的util.jar文件放置在输出文件夹。
相关文章推荐
- VMware View 5.0从菜鸟到高手系列 6 -创建虚拟桌面池篇
- js正则表达式匹配斜杠 网址 url等
- 直接使用Id和使用document.getElementById()的比较
- Mac下安装新版MySQL5.7
- Autoincrement In SQLite
- Java的Scanner类中next()方法与nextLine()方法的区别
- mybatis常用循环语句
- Linux socket编程
- VMware View 5.0从菜鸟到高手系列 5 -配置View Connection Server篇
- POJ 3233 Matrix Power Series (矩阵分块,递推)
- Struts----5大组件
- cf#329-A. 2Char-烦人的水题
- xcodebuild 命令 后面加一个 GCC_OPTIMIZATION_LEVEL=0,这样 就可以调试 了 静态库了
- sql 生成随机数 以及不重复随机数
- ANT教程之八 Ant构建文档
- C语言 ---- 函数 结构体 iOS学习-----细碎知识点总结
- 移动前端开发之viewport的深入理解
- 今日学习札记——数据结构基础(11.7)
- JNI添加外部.so到armeabi目录mk方式
- excel批量分割为印刷版pdf:模板的自动生成