I will start with a mandatory disclaimer: Java-executable JAR files do not work this way. The executable JAR has a main class defined in the MANIFEST.MF JAR file, and MANIFEST also allows you to define the class path to include the libraries that are required for the code in the executable JAR. A class path definition in MANIFEST should list each JAR or folder to host the class path, relative paths relate to the location of the executable JAR β not to paths containing the executable JAR inside . Executable JARs are launched with the -jar argument to the java executable, and both the java flag β-cpβ and the CLASSPATH environment variable are ignored . As to why executable JAR modules were designed in this way, you should be aware of the primary drawback of loading classes from JARs contained in the JAR, although the rest of this answer will focus on this.
NOTE. I lost the original forum topic on the sun, which fully explained this, but essentially because the entries in the top-level JAR can be read in any way, but the entire built-in JAR must be read before any entries can be read, therefore that a top-level JAR could compress its records.
I have used One-Jar in the past, but the structure of the final final jar may not be what you expect. In fact, the One-Jar classes are the only classes other than JARd in the last bank; all other code (your code and any dependent library code) is included in the resulting JAR file as a JAR. Your JARed application is a regular JAR file named "main.jar" in the last main JAR folder. Any libraries your code needs are placed as JAR files in the last JAR folder "lib". And last but not least, the last JAR file MANIFEST.MF tells One-Jar what your main class is. Execution is a dead simple "java -jar final.jar [args that your application uses]". I donβt know how to take the next step to convert to OS-native EXE regarding your custom question, but it is probably best to use a different packaging mechanism than One-Jar. I'm not sure how to do this with NetBeans, my advice is to use the build tool to pack the final jar. Fortunately, One-Jar provides instructions for creating the final jar using Ant, and this should be easily integrated into NetBeans.
I believe the Eclipse FatJar plugin creates an executable JAR with one Jar, so if this plugin seems to do what you want, then One-Jar is the way to do it. Personally, I used the Maven build.
There is a caveat β any signed libraries that require (or desire) to use the Java JAR check may not work that way β an implementation of the Java Cryptographic Extension (JCE) such as BouncyCastle is a notable example. I think the reason is because signature verification works against the final JAR, not from a signed library. Fortunately, One-Jar allows the end user to add additional libraries to the class path, which is explicitly prohibited when running the executable JAR; in order to get around this, you might be better off delivering problematic JARs with a final JAR and OS launching dependent on an OS script (.bat, .sh, etc.).
source share