Search code examples
javaantjavadoc

Copy external docs (from xyz-javadoc.jar) into JavaDocs


I want to create a .jar file with Ant, which contains all JavaDocs of my library and its dependencies. I did a lot of searching yesterday afternoon/evening and this morning, but none of the solutions work for me.

My first solution:

<!-- Generate JavaDoc -->
<javadoc sourcepath="${src}" destdir="${doc}" windowtitle="${ant.project.name}">
   <classpath path="${lib}/nv-websocket-client-2.9-javadoc.jar"/>
   <classpath path="${lib}/gson-2.8.6-javadoc.jar"/>
</javadoc>

My second solution:

<!-- Generate JavaDoc -->
<javadoc sourcepath="${src}" destdir="${doc}">
   <classpath>
      <fileset dir="${lib}">
         <include name="gson-2.8.6-javadoc.jar"/>
         <include name="nv-websocket-client-2.9-javadoc.jar"/>
      </fileset>
   </classpath>
</javadoc>

In both cases, however, only the JavaDoc for my own code is produced. The libraries are completely ignored. In the log of the Ant-Task there are errors, that the classes from the libraries were not found.


Solution

  • I don't know if this is the best aproach, but for me it's easier to use "jar" from command line.

    Then all you have to do is indicate where are your files located:

    jar uf0 path_to_your_jar\your_jar_file.jar path_to_your_files\*.*
    jar uf0 path_to_your_jar\your_jar_file.jar path_to_your_other_files\*.*
    

    If the libraries you want to add are already packed in a jar file, I would extract them first in the root directory, so the path of every file is correct. If you execute the previous commands, you'll have all your files in the "your_jar_file.jar" file.

    if you type jar --help from command line you'll see more options. I hope it helps.