1

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?

0

4 Answers 4

2

..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..

  1. 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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

2

NetBeans IDE handles all these automatically.

  1. New Project -> Java / Java Desktop Application
  2. Press next, fill everything and also check "Use dedicated folder for storing libraries", press finish
  3. Go to the Files view, double click build.xml and from the "Ant targets" list, find the "jar" target, right click "Run target".
  4. 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'm not sure what you mean by step 3. Where is the "Ant targets" list?
This makes the jar executable but it doesn't put the libraries in the generated jar (as the question asks).
@Josh When you double click build.xml, there will be a panel with all the ant tasks, you need to select "jar" from the list, right click and Run target
0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.