Java mystery path in Windows 7 prompt - java

I recently noticed that my PATH setting in Windows had incorrect pointers to older versions of Java. What is odd is that the java -version command still works at the command prompt and it gives the version of Java that does correspond to the latest JRE I have installed. This is also the version represented in Control Panel and it is the VM version referenced by Eclipse. What I'm confused about is how does the command prompt know where to find the java executables if the path is set incorrectly?

There is no mystery. There are going to be at least two versions of Java installed on your computer: The one you installed manually, and the one Windows uses (most likely inside the \system32 folder).
when you type the java command at the command prompt, the operating system (windows) resolves this command by: 1) executing the command located on the current directory, 2) finding the command in one of the paths declared in the PATH.
I have multiple Java versions installed on my computer. The one I want to use to develop software is the one I made sure is declared first on my PATH variable.

Related

jdk-13.0.2 is not visible to the computer because of logisim

I had to install logisim ( a logic circuit editor) but java 5 or any newer edition was required to do so, while i also had downloaded jdk-13.0.2 in order to develop some java projects .I was given this link in order to download logisim:
http://www.cburch.com/logisim/download.html
Also, i downloaded java 8 from the following link:
https://java.com/en/download/manual.jsp?fbclid=IwAR2BoP89O7qYdbWc0Knk5tSSvymVDN-5XF9FdAKo-_OT4pLnnAG-dcxlC9M
Although logisim was succesfully installed to my computer , java stopped working. In adittion vscode reports that no jdk is installed and that classpath system variable points to 0 .
Anyway, I found out that my jdk is stored where it should be ,which means in programm files , while i realised that i had downloaded two more jdks !!! (I still dont know how these got in my computer ...).But this shouldn't really matter because the cmd programm used everytime before starting coding in java still sets the classpath and path system variables at the correct destinations .
The cmd code is the following:
set path="C:\Program Files\Java\jdk-13.0.2\bin"
set classpath=.;C:\Program Files\Java\jdk-13.0.2\lib\tools.jar
(My point is that it doesn't seem to be the above program's fault. )
I also can't find the java edition (java 8) I was supposed to have already to downloaded in order to install and operate logisim with the file explorer.
I really need to keep both logisim and vscode operanotional.
Does it mean that im able to code in java just by having jdk ? ( I wouldn't bother to download java 8 if it wasn't for logisim...).
Also whenever I try to compile a java file using cmd , I get the following error back:
An error has occurred while processing the shared archive file.
Mark mismatch while restoring from shared file.
Error occurred during initialization of VM
Unable to use shared archive.
Any ideas could be helpful.
A new path system variable must be created for the new JRE installation also (the one installed for Logisim). Separate path variables should be there for JDK and new JRE.
For example:
For JDK- D:\PROGRAM FILES\Java\jdk-15.0.2\bin
For JRE- C:\Program Files (x86)\Java\jre1.8.0_281\bin
Path system variable should point to the bin folder of wherever JRE installed.
Path system variables for JDK and JRE. SS from control panel:

Can we install two versions of Java JDK on Windows?

I have created an executable JAR file developed on Java version 8. The JAR file was opening on double click. But as the Oracle applications support only Java 6, I had to install JRE 6, but then after the JRE 6 installation, my executable JAR file is not opening.
I have set the JDK 8 bin path in Path environment variables. Is there a solution for this problem? Why is the JAR file not opening after two Java versions in the system?
JAR should open even if two versions 6 and 8 of Java are installed in the system.
You are facing a backward compatibility problem. Backwards compatibility means that you can run a Java 6 program on a Java 8 runtime, but not the other way around.
You can run a lower configuration on a higher configuration, not vice-versa
There are several reasons for that:
Bytecode is versioned and the JVM checks if it supports the version it finds in .class files.
Some language constructs cannot be expressed in previous versions of bytecode.
There are new classes and methods in newer JREs which won't work with older ones.
If you really, really want (tip: you don't), you can force the compiler to treat the source as one version of Java and emit bytecode for another, using something like this:
javac -source 1.8 -target 1.6 MyClass.java
You can compile your code to Java 1.6 bytecode using JDK 1.8. Just take care of the following:
-source=1.8 and -target=1.6 compiler options
If you use Maven, consider having two pom.xml files, with an optional parent file.
Source: Can program developed with Java 8 be run on Java 7?
I am not sure if this solution going to work or not.
Try to run command java -version and look if it returns java 6 or 8 path. Also try to give path of JDK 8 as JAVA_HOME variable and add that into path like this path=%JAVA_HOME%/bin and see if it works. If you get the java 6 as java version try to use above method and then install JRE 6
Hi All Thank you for your response. I kept java6 and reinstalled java8 and now forms and jar both are working!.
In the short term,
the answer is yes. Since both JDK files are downloaded as jar fils it will ok to download both jar files. The reason to not opening after two java versions is as #Elliott said: "in the system is Java 6 can't run Java 8 compiled code, you should be getting an error." That's exactly true but the problem is how to use multiple versions of JDK in a single machine.
Then we have to move on to long term,
The tricky thing is to manage these multiple JDKs and IDEs. It’s a piece of cake if I just use Eclipse for compiling my code because the IDE allows me to configure multiple versions of Java runtime. Unfortunately (or fortunately), I have to use the command line/shell to build my code. So, it is important that I have the right version of JDK present in the PATH and other related environment variables (such as JAVA_HOME).
Manually modifying the environment variables every time I want to switch between JDKs, isn’t a happy task. But, thanks to Windows Powershell, I’m able to write a script that can do the heavy lifting for me.
Basically, what you want to achieve is to set the PATH variable to add the Java bin folder and set the JAVA_HOME environment variable and then launch the correct Eclipse IDE. And, I want to do this with a single command. Let’s do it.
Open a Windows Powershell.
I prefer writing custom Windows scripts in my profile file so that it is available to run whenever I open the shell. To edit the profile, run this command: notepad.exe $profile - the $profile is a special variable that points to your profile file.
Write the below script in the profile file and save it.
function myIDE{ $env:Path = “C:vraajavajdk7bin;” $env:JAVA_HOME = “C:vraajavajdk7” C:vraaideeclipseeclipse set-location C:vraaworkspacemyproject play }
function officeIDE{
$env:Path = "C:vraajavajdk6bin;"
$env:JAVA_HOME = "C:vraajavajdk6"
C:officeeclipseeclipse
}
Close and restart the Powershell.
Now you can issue the command myIDE which will set the proper PATH and environment variables and then launch the Eclipse IDE.
As you can see, there are two functions with different configurations. Just call the function name that you want to launch from the Powershell command line (myIDE).
If any issue please put a comment below!

See all the Java versions installed on Mac

How can I get all the Java versions installed on my Mac?
Is there a terminal command for this?
When I run java -version, I get the current JRE version that is in use in my system, but I want to list all the JREs installed on my Mac.
/usr/libexec/java_home -V
lists one line per Java environment installed (and known to the /usr/bin/java command).
You can still have other Java distributions which are not registered. They are typically downloaded as ZIP files without an installer, or using another package manager like homebrew.
The accepted solution didn't work for me.
The results it returned didn't include all the Java versions installed.
For example on my machine there are currently 5 installations, but the accepted solution only returns 3.
What eventually did work for me is:
mdfind -name 'java' | grep '/bin/java$'
It finds all java installations on the system regardless of how they were installed. This way I found the specific java installation which I was looking for.
Explanation of how it works:
mdfind is a native tool in MacOS to search for different files by given query, it's very fast (usually way faster than find)
The given command is looking for everything called java and then filter only the results that end with /bin/java which is the typical suffix of java installations

Java -version prints a wrong version

I have multiple versions of Java installed in the environment(I know it is bad). I've set the JAVA_HOME to jdk 1_4 directory. This is not installed, but extracted from zip and placed it somewhere. We have java 1.8 JRE also installed in the system. I never set the path to this installed directory. Now i'm trying to run some ant script that depends on jdk 1_4. I get some exception saying that it is not able to find tools.jar in java1.8... .
My question is that when the path and java_home are set to jdk 14 why does the ant look for 1.8 version of java? I'm confused.
Update: I have looked up the duplicate issue.
Additional details: Java -version prints 1.8 with jdk 14 in the path and java_home. I uninstalled 1.8. reopened cmd tried java -version, now it errors out saying that it is not able to find java1.8 instead of trying to find the next java available in the path or java_home.
Error shown:
C:\Users\usrpao>java
Error: could not open `C:\Program Files\Java\jre8\lib\amd64\jvm.cfg'
I have multiple versions of Java installed in the environment(I know it is bad). I've set the JAVA_HOME to jdk 1_4 directory.
Not wrong at all. I have a similar setup because I have to switch between Java version.
First, install Java JDKs in the root of your drive. No spaces in the directory names. For example, C:\Java\Java-1.6-21 and C:\Java\Java-1.7-5.
In your Environment Variables section in your System Control Panel (under Advance), create an environment variable to point to each one of these Java Home directories. For example, JAVA_HOME_17 = C:\Java\Java-1.7.5 and JAVA_HOME_16 = C:\Java\Java-1.6-21. This should be a System Environment variable.
Create a JAVA_HOME environment variable that points to the Java version you want: JAVA_HOME = %JAVA_HOME_17%.
Now in the System PATH, prefix the PATH (the very first entry) with %JAVA_HOME%\bin.
When you open a console window, your default java and javac commands will be the correct Java version.
If you need to change a version, change the JAVA_HOME environment variable to point to the correct environment variable and open a new console window. Now that new Java will be in your path.
NOTE: It is vitally important that %JAVA_HOME%\bin is in the first part of your PATH before C:\Windows\System32. You don't want the java.exe that exists in that directory to be your default java.
You haven't specified the operating system, so:
on windows, java installs a java.exe in C:\Windows\system32, which is probably on the path before java_home, and so gets picked up
on Linux, various distributions that support multiple installed java versions will also have some symlink earlier on the path. Run 'which java' to determine where that symlink is
Multiple java versions in the system is the problem, I uninstalled all the java versions first. Restarted my machine. Path and java home points to the jdk 1.4. java -version now points to the version specified in the path. Thanks all.

JAVA_HOME and java -version

I'm using a Windows .bat script and I set JAVA_HOME as C:/Program Files/Java/jdk1.6.0_32
when I do a java -version, it still shows the 1.3
How can I fix this? What am I doing wrong?
For me the issue was in my PATH variable, C:\ProgramData\Oracle\Java\javapath; was added by java windows install before my %JAVA_HOME%\bin;.
So I'd echo %JAVA_HOME% pointing to a JDK7 and java -version showing jdk8.
I'd to put %JAVA_HOME%\bin; before C:\ProgramData\Oracle\Java\javapath; so that java -version displays jdk7.
Try %JAVA_HOME%\bin\java -version
If you modify JAVA_HOME, it's usually better to invoke java with an absolute path (using JAVA_HOME) because the new binary is probably not in the path (and then Windows will load the wrong binary).
Make sure that the PATH environment variable is pointing to %JAVA_HOME%\bin.
Be sure not to mix the system variable path and the user variable system path. I feel OK in calling java without the absolute path (when I know how JAVA_HOME and PATH are configured).
Calling java -version from command line, causes cmd.exe to do the lookup on the "known" directories. "Known" means PATH environment variable. It seems that your PATH contains a java 1.3 bin folder, and not 1.6.
JAVA_HOME is another variable, that is used (for example, and not only) by java wrappers, or by scripts executing some java stuff.
Try doing this:
SET JAVA_HOME=C:/Program Files/Java/jdk1.6.0_32
%JAVA_HOME%/bin/java -version
Add quotes where needed.
I had similar issue,in my case , I had two versions java installed. it can be fixed by uninstalling one version of java completely from system.
Had a similar scenario today - two Windows 10 devices - both have JRE 1.6 & 1.7.
When typing
Java -version
One device shows 1.6 the other 1.7.
This was preventing me running a third party JAR to install some software on the device showing 1.6 (which worked fine on the device showing 1.7 when running java -version), using:
java -jar ThirdParty.jar
As the JAR needed to be run by 1.7.
Cause of this was in the PATH environment variable - one device had the location of 1.6 first in the PATH list, moving the 1.7 location above the 1.6 location resulted in consistency using Java -version and allowed me to install the software.
java -version will consult the paths in the special environment variable Path. You need to select the java version you want and move it upwards the latter (click "Move Up"). You probably have that reference to JDK 1.3 in Path above your addition of JDK 1.6. Since that's the first thing the OS finds, that's what it chooses to run.
Executing the command again with the same window opened after changing the environment variables will not work. Re-open it
I know this question is old but this was my case and I wanted to re-explain further, similar to #DanBot 's case

Categories

Resources