简体   繁体   中英

Export Jar File in NetBeans

I am looking for a way to export a .jar file in Netbeans. I know that when I clean/build it automagically puts everything in a .war file in the dist directory. However, in Eclipse you can select Export -> Export -> Java -> JAR file and click next and select only the resources you want to export and select a location to export the .jar file to. Is there any equivalent to this in Netbeans?

you can enable the "Build JAR after Compiling" property in Netbeans

File > Project Properties > Build > Packaging

I ended up just building the project the usual way getting a .war file in the dist folder.
I then used a zip program called IZArc: http://www.izarc.org/ to open the .war and get out only what I needed to build the .jar. I then used IZArc again to create the .jar file.
If anyone knows of an easier way (preferably through Netbeans itself) please let me know.

If you know how to write Ant files, edit the build.xml and add a -post-dist target. Then the jar file will also be created when the war file gets created. Something like:

<target name="-post-dist" description="Create jar file.">
    <!-- Copy your files to a temp directory if necessary. -->
    <copy ...>
       ...
    </copy>

    <!-- 'basedir' should be the directory from which to jar the files -->
    <jar destfile="${dist.dir}/app.jar" basedir="${build.dir}/myjarfiles"/>
</target>

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