Say you have a Java project in Netbeans with a library jar added.
In my case this was SQLiteJDBC, an SQLite JDBC driver for Java applications.
When you build the project (“Clean and build project”) a folder ‘dist’ will be created with as contents:
- Your executable jar file
- A ‘lib’ folder with the jar files of your added libraries inside
In your executable jar file (it’s actually a zip file, you can open it with Winrar for example) there is a folder called ‘META-INF’ with inside a file called ‘MANIFEST.MF’.
Class-Path: lib/sqlitejdbc-v056.jar
This line in ‘MANIFEST.MF’ makes sure that your executable jar file knows that the jar file for the SQLiteJDBC driver library is in ‘lib/sqlitejdbc-v056.jar’
Now, the problem for me was that I wanted a single executable, not an executable with some added library files.
With Java you can easily solve this problem by copying the contents of your library jars into your executable jar.
This means opening sqlitejdbc-v056.jar and opening the created executable jar with Winrar and dragging all the contents from the library jar to the executable jar.
Now, I’m quite lazy and I want that when I click the ‘Clean and Build’ button this all happens automatically.
» Read more: Automatically add library jar contents to executable jar with Netbeans