简体   繁体   中英

Java Netbeans GUI builder make executable jar

因此,由于Netbeans生成的jar需要它也生成的lib文件夹,因此我该如何将lib文件夹添加到生成的jar中并更改Manifest,以使其在不使用任何命令行的情况下启动?

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

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.

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

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)

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