So, since the jar generated by Netbeans requires the lib folder that it also generates, how do I go about adding the lib folder to the generated jar and change the Manifest so that it launches without any command line usage?
4 Answers
..so that it launches without any command line usage?
If it has a GUI, launch it using Java Web Start.
JWS provides many appealing features including, but not limited to, splash screens, desktop integration1, file associations, automatic update (including lazy downloads and programmatic control of updates), partitioning of natives & other resource downloads by platform, architecture or Java version, configuration of run-time environment (minimum J2SE version, run-time options, RAM etc.), easy management of common resources using extensions..
- Desktop integration: desktop shortcut & menu item on supported platforms - no more Command Line based launch!
See Enabling Java Web Start in the NetBeans IDE to get started.
Comments
Although there are many ways to do it, they mostly involve modification of the Ant build.xml. This is the best tutorial I've found so far. FYI, there are other SO questions that are very similar.
Comments
NetBeans IDE handles all these automatically.
- New Project -> Java / Java Desktop Application
- Press next, fill everything and also check "Use dedicated folder for storing libraries", press finish
- Go to the Files view, double click build.xml and from the "Ant targets" list, find the "jar" target, right click "Run target".
This way the generated .jar file will contain all dependencies and have a manifest with the Main-Class set:
Manifest-Version: 1.0 Ant-Version: Apache Ant 1.8.1 Created-By: 1.6.0_26-b03 (Sun Microsystems Inc.) Main-Class: desktopapplication1.DesktopApplication1 Class-Path: lib/appframework-1.0.3.jar lib/swing-worker-1.1.jar
Edited: this does not package libraries into the .jar, but puts them next to it in a separate lib. See @user845279
3 Comments
I ended up using ninjacave.com/jarsplice to compile it all (libraries included) into one executable jar. (I got an error with the background color being the default color even though I had set it to a different color, so I modified the code that jarsplice uses to launch your program using java rather than the path to java)