Java Netbeans-使用Ant将资源文件添加到jar文件

Java Netbeans-使用Ant将资源文件添加到jar文件,java,netbeans,ant,resources,jar,Java,Netbeans,Ant,Resources,Jar,我希望使用Netbeans 6.9将一些资源文件(非代码文本文件)添加到Java项目中的jar文件中,我希望使用Ant。我原以为这会相当简单…但经过相当多的搜索后,我找不到如何做。。!任何指向正确方向的指针?如果选择文件>项目属性>构建>打包,您将看到一个对话框,允许您从构建中排除工件;其他所有内容都包含在源代码树中。的源代码是一个包含html文件的具体示例 对于更高级的任务,请检查为新创建的项目生成的默认build.xml;它识别预定义任务中的各种挂钩。比如说, There exist sev

我希望使用Netbeans 6.9将一些资源文件(非代码文本文件)添加到Java项目中的jar文件中,我希望使用Ant。我原以为这会相当简单…但经过相当多的搜索后,我找不到如何做。。!任何指向正确方向的指针?

如果选择
文件>项目属性>构建>打包
,您将看到一个对话框,允许您从构建中排除工件;其他所有内容都包含在源代码树中。的源代码是一个包含
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 输出:

$ ant compile Buildfile: build.xml ... -post-compile: [echo] build.dir: build [echo] build.size: 11992 compile: BUILD SUCCESSFUL $ant编译 Buildfile:build.xml ... -编译后: [echo]build.dir:build [echo]build.size:11992 汇编: 建设成功
我想我在寻找的答案如下:

在build.xml文件中(根据垃圾神的回答),您可以使用ant构建脚本中已有的钩子添加以下内容:

<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>

正在将文件添加到jar。。。

这会将文件目录及其下的所有文件直接添加到jar文件。

谢谢垃圾神。我已经看到了构建过程中的钩子…但我不确定如何使用它们,并且对不同的网站和博客等感到困惑!您能否提供一个示例,说明如何使用合适的钩子将目录fileDir中的data.txt文件包含在jar文件根目录下的同一位置?@Alistair Collins:我已经详细阐述了上述内容。
<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>