Reputation: 11
There were some initial issues with my javac.exe not working with the rest of the software to be able to compile and run the code, yet I was able to get a .class and .java for the program, so I thought I could use Launch4j to still create the application to execute normally by itself. However, I don't know why the .exe produced does not provide the output I expect.
I used a guide that you are probably aware of to learn to test a "HelloWorld" program since I am new to java and turning actual code into applications. Following the procedures, I was able to get up to testing the javac.exe file, to which I found out my JDK version somehow does not properly install one. I learned from here to check if the javac.exe exists, and that somehow the folder with the java version overrides a similar folder with the javac.exe when installed (yet I couldn't find out how to download and install without that happening). So I decided to just install the newest version of the JDK. I checked and there was a javac.exe file in a separate folder, but the update didn't seem to override the previous version. Following the guide, I was able to check everything, but the output in the end produced an error about the compiling java not matching the runtime. I thought of copying the newer java version with the javac.exe to be in the same path of the runtime [the java folder for the newer version was in Program Files like with the guide but the java folder for the original version was in Program Files(x86) to which I had to adapt the environment variables path accordingly], but that didn't fix anything. Since I learned that Launch4j could bundle the steps with various versions, I thought of seeing if I could just wrap everything to work in an exe file. I was able to produce a file that had no output. Looking here, someone said they could fix their issue by checking off "console" on the "header" tab instead of "GUI" but the only thing that did for me with the new exe file was open the command prompt to show me nothing. I am not sure what to check in the command prompt or if I should know it is the same issue as before. Or perhaps Launch4j can work as is but I just don't know what to put in the environment variables (I think I was able to get the exe without a proper input there in the JRE tab since I didn't have a guide this time)? Should I uninstall the previous version even though the command prompt seems to look there or will something else be missing if I do?
C:\Users\User>java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) Client VM (build 25.201-b09, mixed mode)
C:\Users\User>javac -version
javac 11.0.2
C:\Users\User>cd C:\JavaTest
C:\JavaTest>java HelloWorld
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.UnsupportedClassVersionError: HelloWorld has been compiled by a more recent version of the Java Runtime (class file version 55.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 sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
C:\JavaTest>
C:\JavaTest>dir
Volume in drive C has no label.
Volume Serial Number is 68EF-F43A
Directory of C:\JavaTest
01/28/2019 12:46 AM <DIR> .
01/28/2019 12:46 AM <DIR> ..
01/31/2019 12:56 AM 426 HelloWorld.class
01/27/2019 10:41 PM 25,839 HelloWorld.exe
01/25/2019 12:55 AM 751 HelloWorld.jar
01/22/2019 12:29 AM 114 HelloWorld.java
01/25/2019 01:07 AM 798 HelloWorldconverttoexe.xml
01/27/2019 10:41 PM 802 HelloWorldconverttoexe2.xml
01/25/2019 01:09 AM 1,146 launch4j.log
01/28/2019 12:46 AM 5,102 questiontostackoverflow.txt
8 File(s) 34,978 bytes
2 Dir(s) 561,260,572,672 bytes free
C:\JavaTest>
Despite the output I got showing a JNI error and the version checks not matching, I thought I could get the proper output manually. When that didn't work, I expected the "HelloWorld" message (which is what the program code simply is) to appear from creating an exe file with Launch4j, but both attempts resulted in no output when opening the application (the first time didn't even open the command prompt yet the second time briefly did before closing it out). It seems there is no issue with the actual software and certainly not with the program code, but with the process of running the code after compiling it, and I suppose this continues regardless of the variables for Launch4j. I feel that having the program folder "JavaTest" separate and directly in the local drive is harmless since none of the guides gave me any reason worry about that. I feel if I change anything else, I will make the problem worse. Specifically, if I uninstall the Java 8 version (which oddly is listed as an update even though I am sure I got the whole JD kit from Oracle), I feel I will lose a different part than the javac.exe, as the command prompt doesn't fully direct to version 11 for everything. Any help is appreciated.
EDIT: To clarify how I modified my system variables, JAVA_HOME originally had the value to "C:\Program Files (x86)\Java\jre1.8.0_201" with the bin folder missing "javac.exe"; after installing the newest JDK, I tried both "C:\Program Files\Java\jdk-11.0.2" and "C:\Program Files (x86)\Java\jdk-11.0.2" when copying the "jdk-11.0.2" folder to the same location as the previous version in Program Files (x86), but the command prompt still outputs the older version when I input "java -version"; the same error is produced when I input "java HelloWorld" from the JavaTest folder in the local drive. The "Path" variable has always started with "Program Files (x86)\Common Files\Oracle\Java..." to which I edit in "%JAVA_HOME%\bin" with my confidence in the syntax. With this, I can't see how everything can't be found in the newest JDK, including the initial version check in the command prompt, especially when echo %PATH% command does indeed seem to point to the the newest "jdk-11.0.2" version based on the output in the command prompt.
EDIT2: I am not sure if using the update feature to either automatically or manually update to 11 instead would've prevented the Java system on the control panel from only recognizing the Java 8 version as it does now, yet even with installing Java 11 from a direct download, I am able to work with the control panel configuration. On the user side, when I uncheck the path to Java 8 being enabled and add Java 11 paths both from Program Files and from (x86) either with javaw.exe or the whole folder, the command prompt gives the same result. The systems tab does not even allow me to add a path from the Java 11 version yet does allow me to uncheck enabling the Java 8 version (which still makes no difference).
I have noticed a couple of other differences with my situation from the guide, though I don't know if it matters. The guide's user environment variables seem to still include Java in the path yet the only directions for me were to edit the system variables to go to the Java path. The output from "dir" in the guide shows everything with the same date, yet "dir" in my command prompt only shows an update to the date of the "HelloWorld.class" file (I have added the output for this edit at the end of the code section of the question), which may make sense as I know the older launch4j attempts would not be affected.
I am okay with Java 8, but if uninstalling everything and reinstalling Java 8 does not get the javac.exe file, would moving only the javac.exe file of Java 11 to the bin folder of the Java 8 jre folder work (after resetting the paths to Java 8 and finding a way to get rid of the remainder of Java 11)?
Upvotes: 1
Views: 1346
Reputation: 723
check your PATH, you can check the environment variables or run in windows command prompt (CMD)
echo %PATH%
you should be pointing only to one JAVA version, I suppose that you are pointing to java 1.8.0_201 and to javac from another java (maybe java 11?).
I suppose that you see javac in JDK11 but you do not see javac in JRE8. If you want to use Java 8 then download JDK for java 8 and point to It.
In case you want java 11, remove links to java 8 in your PATH
Upvotes: 0