[英]How do I change the destination directory of Ant's fileset command?
I have an Ant buildfile for a Java library. 我有一个Java库的Ant构建文件。 It looks something like this:
它看起来像这样:
<project ... ><target ... >
<jar destfile="C:\path\to\export.jar">
<manifest> ... </manifest>
<fileset dir="C:\path\to\bin" />
<fileset dir="C:\path\to\src" />
<fileset dir="C:\path\to\doc" />
<zipfileset src="C:\path\to\included\library.jar" />
</jar>
</target></project>
The only problem is that my JavaDoc is being exported directly into the root directory of the resulting jar file. 唯一的问题是我的JavaDoc被直接导出到生成的jar文件的根目录中。 Essentialy, I'd like some equivalent of the
<copydir>
command that can be used inside the <jar>
command. 实际上,我想要一些可以在
<jar>
命令中使用的<copydir>
<jar>
命令。
My desired structure is this: 我想要的结构是这样的:
export.jar
META-INF
Manifest.MF
com
example
whatever
Blah.class
Blah.java
org
external
somelibrary
Magic.class // contents of the included library jar file
doc
// javadoc files here
The current structure is: 目前的结构是:
export.jar
META-INF
Manifest.MF
com
example
whatever
Blah.class
Blah.java
// some javadoc files here
org
external
somelibrary
Magic.class // contents of the included library jar file
// more javadoc files here
My current "solution" is to omit the documentation <fileset>
command, then, once the jar has exported, go into Windows Explorer and right click → 7-Zip → Open Archive ; 我当前的“解决方案”是省略文档
<fileset>
命令,然后,一旦jar导出,进入Windows资源管理器并右键单击 → 7-Zip → 打开存档 ; I can then drop the doc
directory in there just fine. 然后我可以放下
doc
目录就好了。 However, this pretty completely defeats the purpose of Ant as a completely automated build system. 但是,这完全违背了Ant作为完全自动化构建系统的目的。
If it matters, this file was originally generated by Eclipse with the Runnable JAR exporter. 如果重要,此文件最初由Eclipse与Runnable JAR导出器生成。 However, I obviously need to modify it to add source files, etc. because it's a library and not actually a runnable jar.
但是,我显然需要修改它来添加源文件等,因为它是一个库而不是实际上是一个可运行的jar。 I exported it as a runnable jar to get Eclipse to package in the required libraries;
我将它导出为可运行的jar,以使Eclipse在所需的库中打包; apparently libraries on the build path aren't available for export via the standard File → Export → JAR file .
显然,构建路径上的库不能通过标准文件 → 导出 → JAR文件 导出 。
A jar is actually like a zip file. jar实际上就像一个zip文件。 Hence you can use a
zipfileset
. 因此,您可以使用
zipfileset
。 Its attribute prefix
is what you are looking for. 它的属性
prefix
是您正在寻找的。
The zipfileset
command can accept either a zip file via src
or a filesystem directory via dir
. zipfileset
命令可以通过src
接受zip文件,也可以通过dir
接受文件系统目录。 Using the latter, you can add the following command: 使用后者,您可以添加以下命令:
<zipfileset dir="C:\path\to\doc" prefix="doc" />
Also worth to note is that zipfileset supports all attributes of fileset. 另外值得注意的是,zipfileset支持fileset的所有属性。 Thus if you want to include just a single file in a specific location you can use:
因此,如果您只想在特定位置包含单个文件,则可以使用:
<zipfileset file="C:\path\to\doc\file.txt" prefix="doc" />
Further reading: http://ant.apache.org/manual/Types/zipfileset.html 进一步阅读: http : //ant.apache.org/manual/Types/zipfileset.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.