简体   繁体   中英

How to Include External Libraries in a Runnable Jar

So, I'm working on this NetBeans project and it is a jframe that plays a sound using an external library. When I run the application from NetBeans the sound plays, but when I build the application and I launch the runnable jar from windows explorer, the sound doesn't play. I don't think the library is included in the runnable jar. I don't know if it needs reference. How can it be done in NetBeans?

You can use something like this to create a "fat jar" that includes your library (depending on your use, there might be copyright issues). Otherwise, you need to include it in the classpath .

There are a number of methods you could use to achieve this.

  1. Extract the contents of all the Jar's and merge them into a single Jar. The problem with this is if you have any files with matching names, then they will be overridden. This is pain if you're using these files as look ups for services (for example)
  2. You could create a self contained native executable, using something like exe4j (I use this, but you will have to evaluate your own solution) and/or Mac App Bundle . This adds another level of complexity to your build
  3. Bundle all your Jars into a single Jar (leaving them uncompressed), using something like OneJar . I've personally had issues when using a custom class loader to load new classes, but otherwise works well.

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