我想使用Netbeans 6.9将一些资源文件(基于非代码文本的文件)添加到Java项目中的jar文件中,我希望使用Ant。我原以为这会相当简单......但经过相当多的搜索后我找不到怎么做......!任何正确方向的指针?
答案 0 :(得分:9)
我认为我正在寻找的答案如下:
在build.xml文件中(根据trashgod的回答),您可以使用ant build脚本中已有的钩子添加以下内容:
<target name="-post-jar">
<echo>Adding files to jar...</echo>
<jar destfile="dist/jarFileName.jar" update="true">
<fileset dir="${basedir}">
<include name="files/*"/>
</fileset>
</jar>
</target>
这会将files目录及其下的所有文件直接添加到jar文件中。
答案 1 :(得分:2)
如果您选择File > Project Properties > Build > Packaging
,您会看到一个对话框,可让您从构建中排除工件;其他一切都包括源树。 TreeIconDemo
的来源是一个包含html
个文件的具体示例。
对于更高级的任务,请检查为新创建的项目生成的默认build.xml
;它将各种钩子识别为预定义的任务。例如,
There exist several targets which are by default empty and which can be used for execution of your tasks. These targets are usually executed before and after some main targets. They are: -pre-init: called before initialization of project properties -post-init: called after initialization of project properties -pre-compile: called before javac compilation -post-compile: called after javac compilation -pre-compile-single: called before javac compilation of single file -post-compile-single: called after javac compilation of single file -pre-compile-test: called before javac compilation of JUnit tests -post-compile-test: called after javac compilation of JUnit tests -pre-compile-test-single: called before javac compilation of single JUnit test -post-compile-test-single: called after javac compilation of single JUunit test -pre-jar: called before JAR building -post-jar: called after JAR building -post-clean: called after cleaning build products
附录:作为example,此目标会覆盖-post-compile
以打印一些统计信息。
<project name="TreeIconDemo" default="default" basedir=".">
<import file="nbproject/build-impl.xml"/>
<target name="-post-compile">
<echo>build.dir: ${build.dir}</echo>
<length mode="all" property="build.size">
<fileset dir="${build.dir}">
<include name="**/*"/>
</fileset>
</length>
<echo>build.size: ${build.size}</echo>
</target>
</project>
输出:
$ ant compile Buildfile: build.xml ... -post-compile: [echo] build.dir: build [echo] build.size: 11992 compile: BUILD SUCCESSFUL