javac not found after set environment variable - java

I am running on a Windows 7 machine.
I installed Java jdk 1.7.
I have set the Path and PATH environment variable to point to the Java jdk 1.7/bin directory.
Executing java -version in the command prompt yields Java version 1.7.0_45.
However when I execute javac it says that:
javac is not recognized as an internal or external command
I am really stumped on this problem. All other threads seem to get similar issues resolved via changing the environment variable but this is not solving my problem in this situation.
Edit
When I run java -version in Console2 it says that the currently used version of Java is 1.6 and I am not sure why this is the case.

Not sure if this is the cause, but in the path you posted
C:\Program Files\Java\jdk1.7.0_45 \bin
Looks like an extra space in between of "jdk1.7.0_45" and "\bin"
Also it's always good to append ";" at the end.
PATH = C:\Program Files\Java\jdk1.7.0_45\bin;

Chnage it to C:\Progra~1\Java\jdk1.7.0_45\bin and it shall work like magic :)

Related

Confused about what jdk and jre my command prompt is using for java

I was super confused about compatibility on a java tool I was using and ended up downloading different versions of java so now I do not know what versions of jdk or jre I am actually using. When I compile I use -- release 8 in my command prompt, what does that exactly mean?
Currently my programs folder has jdk-18 in the java folder
and my program files(x86) folder has
jdk1.6.0_45
jdk 1.7.0_80
jre 1.8.0_ 321
jre6
jre7
My java home environment variable is C:\Program Files\Java\jdk-18
My classpath has the file C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar
when I type java -version in my command prompt I get
java version "1.8.0_321"
Java(TM) SE Runtime Environment (build 1.8.0_321-b07)
Java HotSpot(TM) Client VM (build 25.321-b07, mixed mode)
So does that mean my cmd uses jre 1.8.0_ 321? What about the jdk? How do I change it if I need to?
When you run java -version - first java found in PATH environment variable is used. To be sure use commands where java (Windows) or which java (Linux) - it will tell you the location.
When you run mvn install - JDK found in JAVA_HOME environment variable is used. To be sure use mvn -version - it will tell you the location.
When you run from IDE - IDE settings matter, usually you specify JDK per project.
When you run javac --release 8 Something.java you are asking compiler to produce output compatible with the version you specified - it has nothing to do with JDK you are actually running it on. This flag was added in JDK 9, so if it doesn't fail for you then it means you are running on JDK>=9.
If you want to be 100% sure just fully qualify the path - for example on Windows "C:\Program Files\Java\jdk1.8.0_152\bin\javac.exe" Something.java
So does that mean my cmd uses jre 1.8.0_ 321?
Yes.
What about the jdk?
Unclear.
Run javac -version and that will tell you what version compiler you will run by default.
The versions of the Java tools that you get when you type java, javac, jar (etcetera) at the CMD prompt are solely determined by the PATH environment variable setting in effect at the command prompt.
The other variables do other things ... but not this.
How do I change it if I need to?
If you want to change what typing java does, change PATH.
Note that the PATH variable is a standard Windows environment variable that affects all* commands, not just the Java tools. There should be lots of tutorials on how to set PATH, and on the Windows CMD prompt in general. You should probably take the time to read them.
You can also just use the absolute path for the Java tools; e.g. "C:\Program Files (x86)\Java\jdk1.7.0_80\bin\java.exe" is probably the correct path for the Java 7 java command. (You can easily check ... and find the correct path by looking at the installation tree.)
Regarding your other variables:
My java home environment variable is C:\Program Files\Java\jdk-18
That is presumably JAVA_HOME. That tells (many) 3rd-party tools which Java tools to use. But unless you have configured PATH to depend on JAVA_HOME, it won't alter what typing java does.
My classpath has the file C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar
That is presumably CLASSPATH. That variable provides a default path that java will use to find classes to load. For example, if you run java com.acme.Example, it will use CLASSPATH to search for the compiled Example class.
So "C:\Program Files (x86)\Java\jdk1.7.0_80\lib\tools.jar" is almost certainly incorrect. (That JAR file contains the classes that implement various Java tools. It doesn't need to be on the classpath, unless your Java application is running one of those tools. And even then there would need to be other things on the classpath for your application to work.
You need to do some reading on what the Classpath is, how it works, and how to set it correctly. Setting it to stuff randomly is a sure fire way to make your Java code not work ...

JPackage Wrong Version (%JAVA_HOME% set to correct directory)

Please help. I'm having issues syncing up my JDK and jpackage versions for creating standalone java programs. The JDK version and the runtime version being included with jpackage are mismatched (JDK16 programs being paired with JDK15 runtimes).
Typing java -version into the command line, it matches up with the current %JAVA_HOME% environment variable configuration, showing JDK16.0.2 (located at C:\Program Files\Java\jdk-16.0.2). This is working correctly.
However the problem becomes more apparent when I type jpackage --version, it reports that it's using JDK15.0.1 - which as far as I know, I've never installed and I'm unsure of where it's running from. This is a problem, since I need to be able to build Java16 programs with jpackage. As it is now, this results incompatible runtimes and JAR files.
I've been googling to no avail. I can't compile my JDK16 programs into installers because it keeps trying to use JDK15.0.1 for the runtime.
For now, I've managed to bypass this strange and seemingly locked configuration by accessing JDK16's jpackage exe manually this way and adding the commands after:
“C:\Program Files\Java\jdk-16.0.2\bin\jpackage.exe”
Any advice is helpful. Perhaps this temporary workaround will be helpful to anyone else with the same problem down the line.
Use the Windows where command to find out what the jpackage command is actually resolving to. It seems clear that jpackage without the full path name is resolving to jpackage in a different installation of Java.
Note that %JAVA_HOME% does not determine how the Windows cmd.exe resolves commands. Command resolution is done according to %PATH%.
The symptoms you describe:
jpackage says %JAVA_HOME% is incorrect but %JAVA_HOME% refers to Java 16
jpackage -version says Java 15 (not Java 16)
"C:\Program Files\Java\jdk-16.0.2\bin\jpackage.exe" works
are all consistent with your %PATH% being incorrect ... and that you do have a Java 15 installation on your machine, and it is on the %PATH% ahead of, or instead of the Java 16 installation you are trying to use.
Note jpackage is no longer an "incubator" tool in Java 16. It has been promoted to full support; see JEP 392: Packaging Tool. So the warnings about incubator mudules are also consistent with jpackage resolving to the wrong Java installation.
This really boils down to understanding what the Windows %PATH% variable is and how it effects the behavior of Windows command shells. (It is analogous to $PATH in Linux, UNIX and Mac OSX command shells.)

Java 9: java.dll not found [duplicate]

why do I get this? How can I fix it?
C:\Users\ash>java version
Error: Registry key 'Software\JavaSoft\Java Runtime Environment'\CurrentVersion'
has value '1.7.0_01', but '1.7' is required.
Error: could not find java.dll
Error: Could not find Java SE Runtime Environment.
The accepted solution for Reinstalling ALL JDKs was a bit harsh.
I too experienced this problem and here is my 2 cents:
This problem started happening since I installed JDK 8 and still had JDK 6 installed. I need for different projects I'm working on.
I noticed I had both a User and a System %JAVA_HOME%, so I removed my User %JAVA_HOME% variable and left only the system one.
I also noticed that in my Oracle installation there was some Java executables and I believe those where the ones conflicting since both my Oracle and Java installations were in my %PATH% variable.
I removed all Java paths from my %PATH% Variable and only left the %JAVA_HOME%\bin at the start of the variable for avoiding any conflicts with the Oracle installation.
I had a similar issue after installing the java 1.8.
To fix this go to Advance System setting --> path and remove
C:\ProgramData\Oracle\Java\javapath;
Removing
C:\ProgramData\Oracle\Java\javapath;
work like charm
Reinstall JDK and set system variable JAVA_HOME on your JDK. (e.g. C:\tools\jdk7)
And add JAVA_HOME variable to your PATH system variable
Type in command line
echo %JAVA_HOME%
and
java -version
To verify whether your installation was done successfully.
I had a similar issue after installing the java 10.0
To fix this go to Advance System setting --> path and remove
C:\ProgramData\Oracle\Java\javapath;
I had to remove the Common Files javapath from the 'Path' that was conflicting, in order to make it work. Now thankfully the java -version works just fine.
C:\Program Files (x86)\Common Files\Oracle\Java\javapath
Make sure your JDK Path variable is directing to the \bin folder and is at the top of the list, because it always uses the first match. By moving it to the top you can make sure that no other path is matched first.
If there's any other entry that has a file called java (such as C:\ProgramData\Oracle\Java\javapath) it will run the command against that file instead of the java file in your JDK. There's no need to reinstall the entire JDK unless your files are corrupt or damaged for some reason.
This problem generally occurs in Windows when your "Java Runtime Environment" registry entry is missing or mismatched with the installed JDK. The mismatch can be due to multiple JDKs.
Steps to resolve:
Open the Run window:
Press windows+R
Open registry window:
Type regedit and enter.
Go to: \HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\
If Java Runtime Environment is not present inside JavaSoft, then create a new Key and give the name Java Runtime Environment.
For Java Runtime Environment create "CurrentVersion" String Key and give appropriate version as value:
Create a new subkey of 1.8.
For 1.8 create a String Key with name JavaHome with the value of JRE home:
Ref: https://mybindirectory.blogspot.com/2019/05/error-could-not-find-javadll.html
I edited my path to put the Oracle JDK at the start of the path and that fixed it.
Problem:
We had the same problem in our Windows 2012 server. We used JAVA_HOME environmental system variable, an we used in the PATH this kind of settings: ...%JAVA_HOME%/bin;...
and no other java related settings was in the PATH.
The problem was we had a space at the end of the value of the JAVA_HOME variable. Like 'C:\Program Files\Java\Jdk 1.8.0_172 ' so the %JAVA_HOME%/bin meant 'C:\Program Files\Java\Jdk 1.8.0_172 \bin'. So because the value was split by space and the system tried to find java.exe at 'C:\Program Files\Java\Jdk 1.8.0_172' where it is obviously not.
Solution was: Delete the space from the end of value of the JAVA_HOME !
Uninstall Java from machine
Check Java folder is deleted from Program Files
Check Registry does not have any instance of Java
Open system Variables and delete the ONLY java path from PATH
Now install the new version again.
Set the Path in System Variables.
This process cleans up all the traces of java and then install fresh java.
Note: This issues occurs when there is multiple installation and uninstall done.
You could be using a 32 bit version of java on a 64 bit environment.
Export the registry hive form HKLM\Software\JavaSoft and import into HKLM\Software\Wow6432Node\JavaSoft. For 1.6 I only needed JavaHome and RuntimeLib values.
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Javasoft]
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Javasoft\Java Runtime Environment]
"CurrentVersion"="1.6"
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Javasoft\Java Runtime Environment\1.6]
"JavaHome"="C:\\Java\\jre"
"RuntimeLib"="C:\\Java\\jre\\bin\\client\\jvm.dll"
None of the above worked for me, unfortunately.
The error solved when I uninstalled the old JDK versions that were installed on my computer. I did it simply with the "Uninstall or change a program" tool (under the Control Panel).
I removed the "C:\Program Files (x86)\Heroku\bin" from PATH variable and the problem has gone. I think it is probably the Heroku require different version of Java. So check all directories in your PATH variable, remove the possible ones may have confliction.
If you face this error in cmd with another error as "could not find runtime environment" after you have done all settings in Environment Variable. Then you just need to run jre.exe in your jdk folder and reinstall it and then recheck it by java -version command. Hope it will help you.
rename file "C:\Windows\System32\java.exe" to "C:\Windows\System32\java_old.exe"
CMD --> java -version
done.
In my case the regedit information was correct and the problem was solved by doing the below:
1) setting JAVA_HOME to jdk - set JAVA_HOME=C:\Program Files\Java\\bin
2) setting PATH to jre - set PATH="C:\Program Files\Java\\bin"
after adding the requirements path as illustrated up and deleting C:\ProgramData\Oracle\Java\javapath;. don't forget to reopen your editor.
Go to CMD and type the following:
SET PATH=C:\Program Files\Java\jdk1.8.0_291\bin
(here jdk1.8.0_291 represents your java version, it may differ for you)

Setting Environment variable in Linux

I am using Maven for my project and I need to set environment variables in my system for it to work. I have set environment variable for maven but it also requires setting up Java environment variable. I am accessing linux through Putty through a remote server. I tried setting up JAVA_HOME environment variable but I get this error:
Error: JAVA_HOME is not defined correctly.We cannot execute /home/z222189/jdk1.8.0_31/jre/bin/java
I used export JAVA_HOME=/home/z222189/jdk1.8.0_31/jre for this purpose
Even when i try to execute the java.exe file directlty in linux I get error
-bash: ./java.exe: cannot execute binary file
Any suggestions on how to resolve this issue?
You shouldn't refer to the jre/ subfolder, as Maven will need a Java compiler and potentially other JDK-only tools.
So just use:
JAVA_HOME=/home/z222189/jdk1.8.0_31
EDIT: (making sure that a correct, working JDK is installed at that location, of course...)
Seems you are in Linux, be sure you get Java for Linux!
Set JAVA_HOME using
export JAVA_HOME=/home/z222189/jdk1.8.0_31
Does not work because java is not there, or the version is not the correct, if you already installed correct java linux version and you dont really know where your oracle-java is installed, you can find this running
which java
which will tell you which binary of java is being called, normally is something like
/usr/bin/java
but you can
readlink -f /usr/bin/java
that will give you something like
/usr/lib/jvm/java-7-oracle/jre/bin/java
ergo
export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre/

Weird issue with environment variables

I have this strange Issue with environment variables on my windows 7 system. Its been there for an year and I have had a work around but I need to solve it now:
I have an environment variable JAVA_HOME set as C:\Program Files\Java\jdk1.6.0_39\. And in my PATH I have added %JAVA_HOME%\bin;.
But when I do java -version it prints "1.7.0_11" and when I do javac -version it prints as expected 1.6.0_39
I do not know why 1.7.0_11 is printed for java -version. I have checked my PATH and have added JAVA_HOME only once. How can I know which env variable is responsible for using my java.exe? How do I avoid it?
It's almost certainly a version of java.exe in c:\Windows\System32, which is likely to come earlier in your path than the part which refers to JAVA_HOME.
Ok, hopefully %JAVA_HOME\bin%; is a typo, but if not, it should be %JAVA_HOME%\bin.
For the rest - java -version is looking for your JRE, not your JDK. javac is looking for the JDK.
Check to see if you have a JRE-related environment variable. As well, check your path for any hard references to the Java 7 JRE. Finally, look in C:\Windows\System32 and see if there is a java.exe there.
Java.exe is installed on windows twice. The first location is where you expect it: under your JAVA_HOME. The second one is under c:/windows. Since this path always wins any other user defined path you are running java from here. If you want to hold several java environments and switch between them by changing your JAVA_HOME just remove java.exe from c:/windows.

Categories