How can I build my jar file so that users who use

2019-07-31 02:26发布

问题:

I'm working on a small library for our in-company use, and have been heavily documenting it. Now I'm building my jar with the following code:

<project name="commonutils" default="compile" basedir="."> 

    <property name="src" location="src" />

    <property name="build" location="buildDirecotry" />

    <target name="compile">
        <delete file="${ant.project.name}.jar" />
        <mkdir dir="${build}"/>
        <javac srcdir="${src}" destdir="${build}" debug="on" target="1.5">
            <classpath>
                <pathelement location="lib/build/server.zip" />
                <pathelement path="${java.class.path}/"/>
            </classpath>
        </javac>
        <jar basedir="${build}" destfile="${ant.project.name}.jar" />
        <delete dir="${build}" />
    </target>

</project>

Which works fine, it builds my jar file with all the src files in it, but when I include the jar file in another project I no-longer have any of my javadoc comments. Using JDDecompiler I cannot see the comments in the class file, although I'm not sure if its the java compiler that's stripping them or JD.

My question is: How can I build my jar file so that users who use the library will be able to see the javadoc in Eclipse.

回答1:

If you include the source files in the jar (each class and java file in the same package-directory) it should work.

<target name="jar.noCompile.src">  
    <jar destfile="${ant.project.name}.jar">  
      <fileset dir="${build}"/>  
      <fileset dir="${src}" includes="**/*.java"/>  
    </jar>  
</target>  


回答2:

AFAIK the documentation is an Eclipse feature. You have to configure it manually. In your build generate the documentation (usually into folder 'javadoc') and package it with the JAR. Once someone wants to use your library, he/she has to go into Java Build Path select libraries, add yours, click next to it to open the tree node and then double click on Javadoc location to configure it.