简体   繁体   中英

How to Embed Javadoc in a Jar for Netbeans

Is it possible to automatically embed javadoc into a jar from NetBeans? In the program there is an option to generate javadoc. This creates a finished website generated from the existing javadoc in your project. There is also an option to attach javadoc to a project or jar so that it shows up in the suggestions. Right now, when I click build and then take the jar and add it to a project on a different computer the javadoc for jar does not show up. I have to manually copy it over to the computer and attach it, which seems redundant when I should just be attached automatically.

Things I tried:

  • Using 'Clean and Build' and just 'Build'
  • Exporting the whole dist folder instead of just the jar.
  • Putting the javadoc inside the jar.

Assuming you're using the default Ant based Netbeans Project, you will need to modify the projects build.xml file to include the generation of the JavaDocs and copy the resulting files into the build.classes.dir so they can be Jar'ed

Start by clicking on the Files tab, next to the Projects tab, expand your project node and you will see the build.xml file in the root directory

文件选项卡

Next, the you need to inject some functionality into the build process, between the compile and jar processed. Reading through information inside the build.xml , the -post-compile target is probably the place we want to get started.

After having a read of the javadoc ant task documentation , I added this to my build.xml

    <target name="-post-compile">
        <javadoc 
            sourcepath="src"
            defaultexcludes="yes"
            destdir="javadocs"
            author="true"
            version="true"
            use="true"
            windowtitle="The name of your API"
        >
            <doctitle><![CDATA[<h1>My API</h1>]]></doctitle>
            <bottom><![CDATA[<i>Copyright &#169; 2000 Dummy Corp. All Rights Reserved.</i>]]></bottom>
            <tag name="todo" scope="all" description="To do:"/>
            <link offline="true" href="http://docs.oracle.com/javase/8/docs/api/" packagelistLoc="C:\tmp"/>
            <link href="http://docs.oracle.com/javase/8/docs/api/"/>                
        </javadoc>
        <copydir src="javadocs" dest="${build.classes.dir}/javadocs"/>
    </target>

So, I placed this directly under <import file="nbproject/build-impl.xml"/> in the build.xml file, but it's placement should matter.

This generated a jar file with the javadocs directory (and the javadocs) included in it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM