Login  Register

Re: Running a JOGL app from a single JAR file

Posted by sasq on Jan 15, 2015; 9:15am
URL: https://forum.jogamp.org/Running-a-JOGL-app-from-a-single-JAR-file-tp4033846p4033858.html

gouessej wrote
Actually, using the packages provided with various GNU Linux distributions is a bad idea even for development purposes.

Perhaps, but it's not the issue right now, as long as the non-JAR version of my test app runs fine.
I'm on Gentoo Linux which compiles everything from sources and usually has everything up to date.
But if they stop running from some reason, I'll upgrade these libs from the JOGL website.

gouessej wrote
Maybe you can simply copy the JOGL JARs into the same directory than the JAR you created (modify the Class-Path attribute too) and you will need to set the Java library path for the native libraries.

Yeah, this way it works fine. Now how to make it run with these JARs embedded into my app's JAR file? When I put the library JARs inside the app's JAR, they are not seen by the class loader.

gouessej wrote
The example I gave you shows which JARs are necessary.

OK, I pretty much learned how to find out which JARs are needed by opening them and looking through them for the class from the error message. Maybe later I'll figure out how to repackage them. But for now, the main issue is how to run the app with all the libraries supplied in the JARs packed inside the main single stand-alone JAR file instead of supplying them separately and having the user copy it into the same directory with my app's main JAR.

Unfortunately, this quote from the Java docs doesn't seem very promising :-/

Note: The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

Unfortunately, they don't explain much about how such "custom code" should look like and how to do it.

gouessej wrote
If you create one JAR per platform, you'll have to hope that the end user won't pick the wrong one

Perhaps I could pre-select it for him by detecting the platform supplied by his browser. That's how many corporate websites do it (such as Oracle with Java, Adobe with Flash etc.). This is not an issue right now. So let's not get into unnecessary details for now, OK? The main issue right now is how to make the JAR self-contained.