在Netbeans中自动生成源和文档jar

时间:2009-05-13 00:16:08

标签: java netbeans ant build jar

有没有办法在Netbeans中自动生成源代码和javadoc jar?理想情况下,我希望每次构建时都将我的源码和JavaDoc的jar放在dist文件夹中。

3 个答案:

答案 0 :(得分:12)

以下是我个人添加到我的ant文件(build.xml)的内容:

<target description="bundle sources in a jar" name="package-sources">
  <jar basedir="src" destfile="dist/${ant.project.name}-sources.jar"/>
</target>
<target depends="-javadoc-build" description="bundle javadoc in a jar" name="package-doc">
  <jar basedir="dist/javadoc" destfile="dist/${ant.project.name}-javadoc.jar"/>
</target>

Netbeans手动调用这些目标,或者您可以使用钩子目标:

<target name="-post-jar" depends="package-sources, package-doc" />

答案 1 :(得分:11)

请尝试将此添加到build.xml。我在NetBeans IDE 7.0上测试过它

<target name="-post-jar" description="bundle sources and javadoc in a jar" depends="javadoc">
    <jar compress="${jar.compress}" basedir="${src.dir}" jarfile="${dist.dir}/${application.title}-sources.jar"/>
    <jar compress="${jar.compress}" basedir="${test.src.dir}" jarfile="${dist.dir}/${application.title}-test.jar"/>
    <jar compress="${jar.compress}" basedir="${dist.javadoc.dir}" jarfile="${dist.dir}/${application.title}-javadoc.jar"/>
</target>

答案 2 :(得分:1)

我在NetBeans IDE 7.2上尝试了以下操作并且它可以正常工作(假设项目名称是 MyProject

  1. 转到 MyProject 目录

  2. 在文本编辑器中打开 build.xml 文件

  3. <import file="nbproject/build-impl.xml"/>行下添加以下行:

    <target name="-post-jar" description="bundle sources and javadoc in a jar" depends="javadoc"> <jar compress="${jar.compress}" basedir="${src.dir}" jarfile="${dist.dir}/${application.title}-sources.jar"/> <jar compress="${jar.compress}" basedir="${dist.javadoc.dir}" jarfile="${dist.dir}/${application.title}-javadoc.jar"/> </target>

  4. 转到 nbproject 文件夹并在文本编辑器中打开 project.properties 文件

  5. 编辑输出二进制文件的名称(默认设置为项目名称.jar): # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/**MyProject-binaries**.jar

  6. 保存并构建项目。
  7. 希望它也适合你。