I have 3 installed versions of java (1.6,1.7,1.8) in my machine. Java alternatives has been configured to Java 1.8. So whenever i type java -version it is picking up from alternatives and showing java 1.8.
Here now i want to use other version of java (1.6 or 1.7), for that i have tried updating the .bashrc with other java paths. But still it is showing alternatives version (1.8)
Is there any way to override alternatives java from user level.
Here is a blogpost explaining how to change jdk version in a *nix environment from terminal:
https://www.jayway.com/2014/01/15/how-to-switch-jdk-version-on-mac-os-x-maverick/
There is no need to change your environment to switch Java version.
You can simply qualify the version you want to use. Alternatively, just make sure the version you want is first on the PATH, not last.
See my old answer for examples. It's for Windows, but it should work similarly for Linux.
https://stackoverflow.com/a/32365879/5221149
Found the fix
I did like below
export PATH:new_java_path:$PATH. Now it started working for the current session.
Related
I want to downgrade from Java 10 to Java 7 for one of my conda environments. I created a copy of an old environment, and now want to downgrade the Java version. Originally I was hoping I could do something like:
conda create --name new-env --clone old-env java=1.7
But that's not possible. Instead, I think I'm supposed to download Java 1.7 and then just change the JAVA_HOME environment variable in my new environment. Is this correct?
Thanks for your help!
When I download and install Java 8 (JRE) from: http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
I can see the folowing registry key:
[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment]
"CurrentVersion"="1.8"
However if I download and install Java 8 (JRE) from:
https://www.java.com/en/download/
I got the following registry key:
[HKEY_CURRENT_USER\Software\JavaSoft\DeploymentProperties]
I need to detect if Java 8 (JRE) is installed, should I check them both? Are there other registry location I need to check?
What’s are the differences between the two installers? Are they both providing the same Java JRE or there are any differences?
Thanks
Maybe I would try different approach, try look for java(w).exe on system variable PATH. It should point to latest installation of JRE - assuming latest directory entry in PATH.
Also if your application require specific JVM then its also possible to include JRE with your application. Just pack it inside and make sure your JRE is started. Many companies doing it for very good reason.
You should consider 32bit installations on a 64 bit machine as well.
In Microsoft's techNet site I found a vbs script to be used to determine the java version. Hope it helps. TechNet article on determining the version of java on windows
how do you determine the update package of your jdk? when i run
javac -version
I get the following 1.7.0
does this mean there have been no updates applied?
should running the update from the java icon in the tray or from control panel update the jDK as well as the JRE or just the JRE
Is there a way to update vs re-install java?
You can use the command line option -fullversion,
java -fullversion
or (as other's have noted),
java -version
or you could use some code
String version = System.getProperty("java.version");
System.out.println(version);
Is there a way to update vs re-install java?
If you use Windows java can check for updates. If you use Linux you can get updates automatically in depend from settings of package manager. More detailed answer depends from your OS.
So I'm trying to get the latest version of Java. When I run:
java -version
I get:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
When I run:
javac -version
I get:
javac 1.6.0_65
Now I've just downloaded and installed JDK 8. When I go into System Preferences --> Java --> Update, I see:
Your system has the recommended vesion of Java.
Java 8 Update 05.
I guess I have a few questions:
1) Don't I want the JDK and my version of Java to match up?
2) Why does my Java Control Panel claim I have Java 8, but my work in the terminal (when checking my Java version) says otherwise?
Thanks for the help,
Mariogs
The probably "simple" answer is you have two versions of java installed. On the command line you currently use 1.6. Thus the old one is active. In system preferences you see the version of java 8.
Windows:
You can change the version of the command line to java 8. Set PATH environment variable and JAVA_HOME or via windows preferences. I recommend the first one.
Mac: /usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac. IMHO this answer is a good solution.
The Java Platform offers both the JRE and the JDK in order for users to run Java programs. The JRE stands for the Java Runtime Environment, and the JDK stands for the Java Development Kit.
The JDK is meant for Java developers - that is, those who build applications/write programs in Java. It contains tools that are needed for Java coding, including -javac to compile programs.
The JRE is meant for regular users - those who only need to run Java programs on their computer and are not interested in development.
The reason for the discrepancy in your case is because you're looking at the JRE and JDK and trying to compare the two. The current JDK that you have is Java 8, whereas the current JRE that you have is 1.6.0_65. It is problematic that your JRE version does not match your JDK version, but without your PATH variable or other information about your install, we can't help you fix your installation.
1) Yes, if you use the JDK at all, you want the JRE (runtime environment) to come from the JDK (development environment) (a JDK necessarily includes a JRE).
2) Likely your path variable is set so that you invoke Java from your Java 6 installation; you need to find the equivalent for your Java 8 installation and set the path for that. Without information about your operating system, we can't help you do that.
We should know the reason for this
Our OS comes with a predefined (built-in)set of tools and utilities. When we try to execute the command e.g. cls in the Windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command.
However, when we install any third party tool/software then path variable is not updated accordingly.
When we install different versions of java on your system then installations go to different directories. E.g. JDK installation directory for Windows will be
C:\Program Files\Java\jdk1.8.0_161
Similarly, JRE installation directory for Windows will be JDK installation directory for Windows will be
C:\Program Files\Java\jre1.8.0_161
We need to update the path variable of OS to point to the appropriate directory. If we set the path of JDK then it will execute a binary from JDK bin directory.
Solution
we need to update JDK or JRE version specific directory location into PATH Environment variable.
Let me see if I can clear it up for you.
1)Yes, arguably you nearly want this to be true.
2)It could be few things, but most likely that a previous instillation was not properly removed. So one gets called instead of the other.
I'm trying to run a parser built in Java, but every time I try to use the class, I get the above error ("Exception in thread "main" java.lang.UnsupportedClassVersionError: danbikel/parser/Trainer (Unsupported major.minor version 50.0)").
From what I've read, this may be a problem with a mismatch between the versions of Java used to compile and run the code; but I've made sure that my JAVA_HOME environment is set to version 1.6, which is the version recommended by the parser's installation guide.
There are older versions of Java installed on the server, but I can't do anything about that. Is there anything else I can do about this error?
Use sudo update-alternatives --config java and set the version you may want to use if you are using a Debian-derived distro (such as Ubuntu).
Aside from setting JAVA_HOME appropriately (which you've done), ensure that you're executing the right version of the java executable. e.g., on Debian or Ubuntu, execute /usr/lib/jvm/java-6-openjdk/jre/bin/java directly, if /usr/bin/java points to the wrong version.
You can use the -version option to verify the version of the launcher you're using. Try java -version and /usr/lib/jvm/java-6-openjdk/jre/bin/java -version and see if the output is any different.
Making sure that JAVA_HOME is set to a particular Java installation is not necessarily enough.
If you have more information on your server and the configuration environment used it would be helpful.
I would make sure that your PATH environment includes ${JAVA_HOME}/bin:${PATH} if you want to make absolutely sure you are using the correct version.
It is likely that your java veriosn is still 1.5 even if you have set JAVA_HOME to 1.6
Type java -version on the console and see what version it prints.
I also had this problem and I resolved it after I found that I had set a custom JAVA_HOME value in my .bash_profile.
I commented this out, loaded a new console and now my project builds.
For me this worked:
1) install JRE 7
2) Install JDK
3) Go to Project Properties>Java Compiler. Set Compiler Compliance level to 1.7.Once you press 'Apply', it would ask you to rebuild the program. For most people that should do it.
For the rest, see a warning section(marked with an yellow '!' mark) appears at the bottom of the Properties window, where it asks to search for the compatible JRE.
Choose either to configure installed JREs or set your environment variable. Once you are done, you are good to go!