I want to use Launch4j to convert my JAR file into Windows executable, so users of my Java program do not need to install Java on their device, but I am encountering some issues.
I exported my Java program as a runnable JAR file, which can be run in cmd (java -DAPI_KEY="my-api-key" -jar .\test.jar); however, when I use Launch4j to generate a exe file and execute it in cmd, it does not work. Here's the error message:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Test has been compiled by a more
recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only
recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:59)
I am assuming that the configuration settings in Launch4j is not set up correctly since JAR file works but not the exe file. Here is the output folder structure:
.
|- jre
| |- bin
| |- legal
| |- lib
| |- ...
|
|- somedata.xlse
|
|- Test.exe
Here is my settings in Lauch4j:
- Basic
- Output file: Path\to\Test.exe
- Jar: Path\to\test.jar
- Header
- Header type: Console
- Single instance
- Allow only a single instance of the application: Checked
- Mutex name: Test
- JRE
- JRE paths: jre (I copied the jre files to the same folder as Test.exe)
- Min JRE version: 1.8.0
- JVM options: -DAPI_KEY="my-api-key" (The environmental variable that does not get exported from Java IDE)
The desired out come is that I want to run the exe file automatically at 11am everyday. I will place this exe file on a server that does not get turned off along with a batch script to run it. If anyone can let me know why the exe file is not working, that would be great!
Any input is appreciated.