Automatically generating source and doc jars in Ne

2019-02-12 12:10发布

Is there a way to automatically generate source and javadoc jars in Netbeans? Ideally I would like to place jars of my source and JavaDoc in the dist folder each time i build.

3条回答
唯我独甜
2楼-- · 2019-02-12 12:37

Please try adding this to build.xml. I've tested it on 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>
查看更多
三岁会撩人
3楼-- · 2019-02-12 12:38

I tried the following on NetBeans IDE 7.2 and it works (assuming that the project name is MyProject)

  1. go to the MyProject directory

  2. open build.xml file in a text editor

  3. add the following lines under the line <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. go to nbproject folder and open the project.properties file in a text editor

  5. edit the name of the output binary file (set to the project name.jar by default): # This directory is removed when the project is cleaned: dist.dir=dist dist.jar=${dist.dir}/**MyProject-binaries**.jar

  6. save and build project.

Hope it works with you too.

查看更多
家丑人穷心不美
4楼-- · 2019-02-12 12:47

Here is what I personally add to my ant files (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>

With Netbeans call these targets manually, or you can use hook targets :

<target name="-post-jar" depends="package-sources, package-doc" />
查看更多
登录 后发表回答