12

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.

Daniel
  • 10,115
  • 3
  • 44
  • 62
Chad Lowe
  • 721
  • 1
  • 6
  • 12
  • What type of project are you creating, Java, Maven, Java Free-Form? The answer would change depending upon the project type. – Mike Cornell May 13 '09 at 12:53
  • It is a netbeans project, I think it uses ant? Ant is on my list to figure out, but the list is long...:) Not Maven, not familiar with that. I guess freeform. Sorry, no formal code education. I have picked up what little i know from books and helpful people. BTW, Thanks. – Chad Lowe May 17 '09 at 04:32

3 Answers3

13

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" />
Andrew Janke
  • 23,508
  • 5
  • 56
  • 85
  • 1
    Thanks for answer. Do I just add the lines in build.xml. Because it didn't work for me. What does "With Netbeans call these targets manually, or you can use hook targets" mean? – hrzafer Oct 26 '10 at 11:52
  • Yes, these targets can be added inside the `` element in `build.xml`. – james.garriss Aug 07 '14 at 18:06
12

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>
user805575
  • 121
  • 1
  • 3
2

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.

Tiago Almeida
  • 14,081
  • 3
  • 67
  • 82
Keenoar
  • 21
  • 1