Can the JAVA_HOME environment variable refer to JDK 11 (e.g. jdk-11.0.8) while running Codename One applications under Eclipse 2020-06?
Or does it need to point to JDK 8 (e.g. jdk-1.8.0_241)?
I am having the following error when I try to run Hello World app under Eclipse 2020-06 when JDK 11 is set to JAVA_HOME:
BUILD FAILED
...[shortened for brevity]...\HiWorldPrj\build.xml:106: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre1.8.0_241"
I am positive JAVA_HOME points to JDK 11 (because I can echo it from command line).
But I think I got this error because tool.jar is removed in JDK versions 9 and up and com.sun.tools.javac.Main used to be under tools.jar?
Yes you can use JDK 11 but your problem seems that the JAVA_HOME is set to the JRE and not the JDK.
Check this answer. The JRE alone cannot compile Java code.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "C:\Program Files\Java\jre1.8.0_241"
Find where your JDK 11 directory is and set the JAVA_HOME environment variable to that path.
However I recommend that you set the Java in the Eclipse configuration tab. You'll find that at "Windows menu -> Java -> Installed JREs".
Update 1
It seems that Codename One uses JAVA_HOME, it is set up in the build.xml. So forget what I said about the Eclipse variables for now.
<property name="javaHome" value="${env.JAVA_HOME}"/>
Make sure your environment variable JAVA_HOME is set to the JDK 11. You can see dos on how to set that here.
Update 2
Also, you'll need to update every source="1.5" and target="1.5" in the build.xml file to either 1.8 or 11.
Example of the change in the eclipse.ini:
-vm
C:/Users/evand/Downloads/openjdk-11.0.2_windows-x64_bin/jdk-11.0.2/bin/javaw.exe
Your JAVA_HOME refers to the JRE, and JRE does not contain javac Java Compiler.
You need to point your JAVA_HOME environment variable to the JDK, i.e. the root directory of the Java binaries.
If your console prints the address of JDK 11 when you echo JAVA_HOME, then it might be that your IDE is configured to override that variable with the JRE directory when you're using that IDE.
Alternatively, your IDE can be using its bundled JRE, and your system might be referring to another Java binaries (JDK, in your case).
Related
This is what my CMD looks like. I have JDK 11 but for some reason it shows my version is 1.8. My netbeans uses JDK11. How do I update it from version 1.8?
EDIT: This is JAVA_HOME
and Path
Windows will run whatever Java is first in your PATH. Therefore, you might want to check your environment variables and also check JAVA_HOME, when you're at it.
Go to Environment variables > JAVA_HOME > Edit > paste the path of your JDK 11 here instead of JDK-8 path > Go to PATH and now paste the path of the bin folder of JDK 11 here and press ok
You can check the version of JDK now over CMD.
Explanation:
ClassPath decides where all commands will be present.Java code should be locatable & is located using classPath where you specify root directories of all projects that you want to run.
I am attempting to install JDK 13 with the accompanying JRE.
I set these environment variables:
JAVA_HOME to C:\Program Files\Java\jdk-13.0.2
JRE_HOME to JAVA_HOME\bin
as per online instructions.
But when I try:
java Greetings
I get an error message that reads like: "JRE incompatible with with JDK 13 compiler".
java -version says "java version 1.8.0_241"
The Java Control Panel lists:
Product: 1.8.0_241 Path: C:\Program Files\Java\jre1.8.0_241\bin\javaw.exe
Product: 13.0.2 Path: C:\Program Files\Java\jdk-13.0.2\bin\javaw.exe
I can delete the entry for 13.0.2 but not the entry for 1.8.0_241
What am I missing?
The JAVA_HOME variable is used by many programs (e.g. Eclipse IDE and the Maven build processor) to find the Java Runtime.
However, the CMD shell searches executables by the PATH variable. You need to add the path to java.exe to the PATH variable as well. Also ensure that you do not have multiple Java versions in the PATH because the first one will be executed.
Please note that all environment variables can be configued for all users system-wide and also for each account personally. This causes confusion sometimes.
I am not able to start eclipse on Windows 7. It was working fine yesterday. Here is the screenshot of error when I start eclipse:
Java versions from CMD
Why it gives different versions for java and javac?
My java home is set to Jdk 7 as below:
JAVA_HOME = C:\Program Files\Java\jdk1.7.0_60
Note: I have jdk 8 installed on my machine but I have not set jdk 8 path.
This question has been asked couple of times but I am not able to resolve it on my machine so please do not mark it as duplicate.
In the environment variables check your path whether it is starts with C:\ProgramData\Oracle\Java\javapath
if yes then please remove it and try again
More than likely you've installed JDK 1.70_60 prior to installing JRE 1.8.0_51.
This would mean that your compiler javac is found within the JDK distribution (Java Development Kit) and your java runtime is found within the more recently downloaded JRE (Java Runtime Environment). JRE does not contain the javac (Java compiler).
I was recently facing the same issue, Java 8 installer prepends to the Windows PATH variable C:\ProgramData\Oracle\Java\javapath that is why you are seeing different versions for java and javac
Your eclipse might not be pointing to the right JDK.
Open your eclipse.ini configuration file for editing. This can be found in the same folder with eclipse.exe file.
replace:
-vm C:\ProgramData\Oracle\Java\javapath\javaw.exe
with:
-vm
C:/Program Files/Java/jdk1.7.0_60/bin/javaw.exe
Then, restart eclipse.
I have recently installed jdk 8. Java 8 installer prepends to the Windows PATH variable C:\ProgramData\Oracle\Java\javapath and this is the reason I was seeing different versions for java and javac
For those who runs on the same issues, I have found nice explanation here
I just downloaded Eclipse, and it said "Version 1.7 or greater is required" for Java. Then I downloaded Java 1.7 and installed it and all that, and even restarted my computer. When I check my Java version in the terminal, it says Java 1.7, so why can't Eclipse recognize Java 1.7?
Thanks a lot! :)
My question isn't a duplicate of Running Eclipse on Mac - JVM Version 1.7 or greater is required because I installed the entire JDK 7 and my computer recognizes Java 1.7. Right now, I can't even open Eclipse.
EDIT:
current steps I have taken:
1) finding the path (/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home) to java 1.7 with command "/usr/libexec/java_home -v 1.7"
2) pasting this path by adding the following in the eclipse.ini file,
-vm
/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home
Error message is still:
Version 1.6.0_65 of the JVM is not suitable for this product. Version: 1.7 or greater is required.
I am sure you must have done this but just in case you haven't can you make sure the environment variable's are set for Java
Have you tried Window -> Preferences -> Java -> Installed JREs?
There you can add (Using the Standard VM option) a JDK (or JRE) by setting the path to the JDK install directory.
right click on
project --> properties --> java compiler
and see the jdk compiler compliance level option set to 1.7 compiler, if not change it to 1.7 or higher
EDIT :-
eclipse by default will take java installation path from %JAVA_HOME% variable, firstly you check whether you have set JAVA_HOME path in your machine.
or you can manually set java path in eclipse.ini file as said in this post
How do I set the Java path in Eclipse so I can run it on an external drive?
and
How to specify jdk path in eclipse.ini on windows 8 when path contains space
I'm using JDK 1.6 at the moment, but I need to use JDK 1.5 now. I have installed the JDK 1.5. I really don't have an idea to set the path. I tried by setting this in the Environment variables:
JAVA_HOME = C:\Program Files\Java\jdk1.5.0
PATH = C:\Program Files\Java\jdk1.5.0\bin
But still when I check the version in the command prompt it says JDK 1.6.
How do I change it?
I'm using JDK 1.6 at the moment, but I need to use JDK 1.5 now.
No, you don't. Use the cross-compilation options, including and especially the -bootclasspath option, and the code generated by the Java 6 compiler should be as compatible with Java 1.5 as if it had been compiled with a 1.5 JDK.
If you are using the same window after having edited the path variable, as Jayan suggests, try to close the Window DOS windows and open a new one and then check the version.
In command-line windows type:
set JAVA_HOME = C:\Program Files\Java\jdk1.5.0 **hit enter and then type**
set PATH = %JAVA_HOME%\bin **hit enter and then type**
set
Now you will see a list of system variables. You can find PATH and JAVA_HOME and their values.
If the above values are correct, as you typed previously in a command prompt, type:
javac -version
The version will be JDK 1.5.xx, and now you can use Set JAVA_HOME variable in Windows to create system variable in Windows.
This is all OK if you compile your code with JDK 1.5 and running with it. Else check the post by Andrew.
You may have to edit PATH variable to have the entries correctly ordered.