Java – Automatically generating source and doc jars in Netbeans

antbuildjarjavanetbeans

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.

Best Solution

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