如何复制文件到使用Ant的现有JAR? [英] How do I copy files into an existing JAR with Ant?
问题描述
我有一个需要它自己的JAR文件中访问资源的项目。当我创建的JAR文件的项目,我想一个目录复制到JAR文件(我猜的ZIP相当于将增加的目录到现有的ZIP文件)。我只希望这个JAR已经创建(和我显然不希望,如果我清理并删除JAR文件发生副本)后发生的副本。
I have a project that needs to access resources within its own JAR file. When I create the JAR file for the project, I would like to copy a directory into that JAR file (I guess the ZIP equivalent would be "adding" the directory to the existing ZIP file). I only want the copy to happen after the JAR has been created (and I obviously don't want the copy to happen if I clean and delete the JAR file).
目前构建文件看起来是这样的:
Currently the build file looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<project name="foobar" basedir=".." default="jar">
<!-- project-specific properties -->
<property name="project.path" value="my/project/dir/foobar" />
<patternset id="project.include">
<include name="${project.path}/**" />
</patternset>
<patternset id="project.jar.include">
<include name="${project.path}/**" />
</patternset>
<import file="common-tasks.xml" />
<property name="jar.file" location="${test.dir}/foobar.jar" />
<property name="manifest.file" location="misc/foobar.manifest" />
</project>
一些构建任务是从另一个文件(共tasks.xml),我不能在这里显示调用。
Some of the build tasks are called from another file (common-tasks.xml), which I can't display here.
推荐答案
该JAR /耳Ant任务是更普遍的邮编任务。这意味着,你也可以使用 zipfileset
在你的jar任务:
The Jar/Ear Ant tasks are subtasks of the more general Zip task. This means that you can also use zipfileset
in your Jar task:
<jar destfile="${jar.file}" basedir="...">
<zipfileset dir="${project.path}" includes="*.jar" prefix="libs"/>
</jar>
我也看到你定义一个单独的清单文件纳入到瓶子里。你也可以使用一个嵌套的清单
命令:
<jar destfile="@{destfile}" basedir="@{basedir}">
<manifest>
<attribute name="Built-By" value="..."/>
<attribute name="Built-Date" value="..."/>
<attribute name="Implementation-Title" value="..."/>
<attribute name="Implementation-Version" value="..."/>
<attribute name="Implementation-Vendor" value="..."/>
</manifest>
</jar>
这篇关于如何复制文件到使用Ant的现有JAR?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!