Login  Register

Re: Running a JOGL app from a single JAR file

Posted by gouessej on Jan 15, 2015; 10:11am
URL: https://forum.jogamp.org/Running-a-JOGL-app-from-a-single-JAR-file-tp4033846p4033859.html

sasq wrote
<p>Perhaps, but it's not the issue right now, as long as the non-JAR version of my test app runs fine.<br/>
I'm on Gentoo Linux which compiles everything from sources and usually has everything up to date.<br/>
But if they stop running from some reason, I'll upgrade these libs from the JOGL website.</p>
Which version of JOGL does Gentoo provide? As far as I know, only Debian (thanks to Sylvestre) provides JOGL 2.2.4 right now, other distros provide only JOGL 2.0.2 and JOGL 1.1.1. If something goes wrong, we'll be able to help you only if you use the very latest version.

sasq wrote
<p>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.</p>
Then, you're not creating a fat JAR, you're trying to apply the method called "Jar-in-Jar", it's doable with or without Eclipse:
http://jogamp.org/wiki/index.php/JogAmp_JAR_File_Handling#Eclipse

However, I haven't tested it, I can't help you and if you have a very old version of JOGL 2, it won't work. Please look at the bottom of the page above, it shows how to set the classpath in this case.

sasq wrote
<p>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.</p>

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

Note: The <code>Class-Path</code> 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 <code>MyJar.jar</code> contains another JAR file called <code>MyUtils.jar</code>, you cannot use the <code>Class-Path</code> header in <code>MyJar.jar</code>'s manifest to load classes in <code>MyUtils.jar</code> into the class path.
<p>Unfortunately, they don't explain much about how such "custom code" should look like and how to do it.</p>
This problem is already solved in JOGL but please use the example I gave you as is first. If you complicate things now, you will never succeed in making it work.

sasq wrote
<p>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.</p>
Don't get into unnecessary complications and you'll make your self-contained JAR very soon. The very first example I gave you is rudimentary, it makes a single JAR from GlueGen, JOGL and your application JAR:
http://forum.jogamp.org/Fat-jar-deployment-method-ant-recipe-tp4032213p4032229.html
Julien Gouesse | Personal blog | Website