Unix Java path variables is being reset - java

I have a machine running RHEL 6. Currently JDK 7 is installed. For ElasticSearch I need to move to JDK 8. SO i copied the JDK 1.8 to /opt/. THen ran the below steps.
update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_45/bin/java 100
update-alternatives --config java
Did the same thing for Javac as well.
Then did the below changes to Environment variables
export JAVA_HOME=/opt/jdk1.8.0_45/
export PATH=/opt/jdk1.8.0_45/bin:...
In setting path, i copied the existing path, removed the jdk7 entries and added the entire path again.
After this when i ran java -version i got 8. But on restarting the shell, it reverted back to 1.7!!!
So i checked internet and found that i need to update the /etc/profile file
So added below two entries..
export JAVA_HOME=/opt/jdk1.8.0_66/
export PATH=/opt/jdk1.8.0_66/bin:$PATH
But even afer this, the JDK 1.7 is being append to teh Path variable.
Any pointers on how i can move to JDK 1.8

I got it working. There was a script file inside /etc/profiles.d/. It was named as jdk.sh. There the JAVA_HOME and PATH was being set. I changed this to the jdk1.8 and the issue was solved. Thanks. i got a comment from Stackoverflow about the way to set the Path using script inside profile.d folder. So searched there and found the script. Took me 2 hours to figure this out... – Shabin Hashim

Related

JAVA_HOME path updated for version 11, java version in the cmd still showing 8

I had recently installed java 11 and set all the necessary paths in the system environment variables.
why does my java -version show the old java installed. Do i need to do something else to get his updated.
You need to add %JAVA_HOME%\bin to your path.
I have noticed that older Java versions put a copy of java.exe and javaw.exe in a directory and reference it from there. That directory, I think, does not contain javac.exe so javac -version is fine but java -version is not fine.
So, java -version is still referring to old java.exe which is there somewhere in your file system.
Do "where java.exe" on command prompt to find where you have java.exe.
Then delete the older versions of java.exe and javaw.exe. Then try doing java -version again.
It is worked for me:
Steps:
You need to add %JAVA_HOME%\bin to your path
Do "where java.exe" on Command Prompt to find where you have java.exe
Then delete the older versions of java.exe and javaw.exe. Then try doing java -ve2sion again.

I want to install Java JDK 8 on mac, but .bash_profile won't detect JAVA_HOME

I'm trying to get Java JDK 8 on my mac. I'm currently running the newest, update to date version 10.0.2 on macOS High Sierra 10.13.6.
I tried to nano .bash_profile and export the command
export JAVA_HOME=$(usr/libexec/java_home -v 1.8)
and then source .bash_profile and it says:
-bash: usr/libexec/java_home: No such file or directory
I tried googling and searching here, but nothing helped so far :/
Your path to java_home is relative and hence cannot be found by your bash script. Try using:
/usr/libexec/java_home
Note: the initial / makes it an absolute path.

IntelliJ can't find tools.jar without sudo

I'm trying to run IntelliJ on Ubuntu 14.04. I've read this question but the solutions don't apply -- I've definitely got the JDK installed rather than the JRE. When I try to run idea.sh, I get the error message:
'tools.jar' seems to be not in IDEA classpath. Please ensure JAVA_HOME
points to JDK rather than JRE.
JAVA_HOME is set to /etc/java-7-openjdk. Eclipse (in the form of Eclim) has no problem finding it. javac -version prints javac 1.7.0_55.
However, if I run sudo ./idea.sh, IntellJ launches fine. What am I missing?
I had the exact same problem half an hour ago. Took me exactly that half hour to fix it, this is how it worked for me:
Short version:
add
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
to your .bashrc, source it and you are fine.
Explanation:
After installing the JDK in Ubuntu there are multiple folders on your disk.
The root folder is
/usr/lib/jvm/java-7-openjdk-amd64/
under which the aforementioned /jre -Folder resides.
The whole problem is, that the jre/lib -Folder does not contain the tools.jar - File searched by the IDE.
Only the /usr/lib/jvm/java-7-openjdk-amd64/lib - Folder does.
To get everything working you have to specify /usr/lib/jvm/java-7-openjdk-amd64 as JAVA_HOME.
Setting /usr as your JAVA_HOME wont solve the problem as that is symlinked to /etc/alternatives which is symlinked to our old friend the /jre-Folder.
I hope this helped you!
In the 64 bit Debian 7, I solved the problem by adding this two lines of code in idea.sh under the /path/to/intellij-folder/bin/
export IDEA_JDK=/path/to/jdk/
export JAVA_HOME=/path/to/jre
And I hope it will solve the problem in Ubuntu.
It turns out JAVA_HOME was set wrong, I needed to set it to:
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
to get it working. I'm not sure why this hadn't caused me any problems before.
EDIT: This setting makes Maven angry (although Maven via IntelliJ works fine). For future readers, I believe the correct setting is:
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/jre/
you can change your current java version as follows
alternatives --config java
alternatives --config javac
but before them you need to install your newly installed JDK in alternatives properly:
alternatives --install /usr/bin/java java [new-jdk-path]/bin/java 120 --slave /usr/bin/rmiregistry rmiregistery [new-jdk-path]/bin/rmiregistry --slave /usr/bin/keytool keytool [new-jdk-path]/bin/keytool --slave /usr/lib/tools.jar tools.jar [new-jdk-path]/lib/tools.jar
alternatives --install /usr/bin/javac javac [new-jdk-path]/bin/javac 120 --slave /usr/bin/jar jar [new-jdk-path]/bin/jar --slave /usr/bin/rmic rmic [new-jdk-path]/bin/rmic

How to fix error: could not find the required version of the Java(TM) 2 runtime environment in '(null)'

I have researched this and none of the solutions that I have seen have fixed my error.
What is happening is I tried to install Java EE version got the above error and then found out that I must install Java SE first. So I installed Java SE and set the JAVA_HOME variable to C:\Program Files\Java\jdk1.8.0 which is where I installed my JDK. I also put C:\Program Files\Java\jdk1.8.0\bin in my PATH variable. Still not working. I also tried the JAVA_HOME variable with C:\Program Files\Java\jdk1.8.0\bin and that didn't work. I also tried installing without the PATH variable being updated to where I put my JDK.
I'm really getting confused as to why this is happening. I've had Java before and I don't recall having this much trouble installing it.
PS I don't install from the command line I just click the download icon in Firefox and then click the download.
Try running the installer at your commandline and pass the path of the JRE instead of the JDK.
For Example:
java_ee_sdk7-windows.exe -j "C:\Program Files\Java\jre8"
I had the exact same problem and even downloading the version without JDK didn't help!
I simply installed it from the terminal with passing the JRE For Example:
java_ee_sdk7-windows.exe -j "C:\Program Files\Java\jre7"
and it worked like a charm!
I had the same problem but an additional step was required in order to install using the command line. In the command window (on my Windows 10 laptop) I had to use:
cmd /d
to tell the cmd window to ignore registry AutoRun commands before the java installation executable would run. After using cmd /d, and changing to the directory where the .exe file was at, the following worked:
java_ee_sdk-6u4-jdk7-windows-x64.exe -j "%JAVA_HOME%"
Where JAVA_HOME is a system environment variable pointing to an existing JDK installation (C:\Program Files\Java\jdk1.8.0_65).
Uninstall everything, all of it.
Then go to your Program Files folder (and (x86) folder if on a 64bit Windows) and physically remove any Java folders.
Reinstall Java SE and then the EE packages. Sometimes Windows appears to get a bit confused and you need to help it figure out what to do.
If you want to uninstall, go to the glassfish folder and open the command prompt, then type:
uninstall.exe -j <The path to your JRE>
These points may be helpful.
java EE SDK7 contains glassfish v4.0 and it compatible with JDK6 and JDK7.
java EE SDK8 contains glassfish v5.0, it compatible with only JDK7 and JDK8, not JDK 9 or beyond.
So environment variable JAVA_HOME has to point to the root directory of one of the mentioned JDK. and %JAVA_HOME%\bin should be added to environment variable path
Despite having followed all of the above, setup of java EE SDK7 gets error:
could not find the required version of the Java(TM;
as Bakudan and laf8 said,
open cmd using run, with /d /a options as followed.
cmd /d /a
and next run SDK7-setup with -j option like this command
sdk7.exe -j "%JAVA_HOME%"
note that %JAVA_HOME% enclosed BY ""
This was happening to me when I tried to run the Java EE installer. What I did, was to download from Oracle a Java EE version which didn't include the JDK, because it was already installed in my system. Problem solved!
Open regedit.
goto :HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\
set CurrentVersion to desired JDK version.
Check JavaHome and RuntimeLib path's for selected jdk version folder
Check JavaHome and RuntimeLib path's for selected jdk version folder
example: "HKEY_LOCAL_MACHINE\Software\JavaSoft\Java Runtime Environment\1.7".
example:
JavaHome=C:\Program Files (x86)\Java\jdk1.7.0_79
RuntimeLib=C:\Program Files (x86)\Java\jdk1.7.0_79\jre\bin\server\jvm.dll
Source: http://tech-read.com/2009/05/19/how-to-solve-error-could-not-find-java-runtime-2-environment-while-opening-an-ide/

Switch from open jdk to Sun jdk

I have jdk1.7.0 directory in /usr/lib/jvm along with other open-jdk versions. I want my Ubuntu 12.04 to treat this jdk(jdk1.7.0) as its primary jdk i.e. I dont want to use open-jdks.
When I type java -version or javac -version, both the times it returns that it is using openjdk and its jre. How can change it to jdk1.7.0?
Put something similar to following to your ~/.bashrc
export JAVA_HOME="/usr/lib/jvm/jdk1.7.0"
export PATH="$JAVA_HOME/bin:$PATH"
for loading the changes, you can just run new bash by typing "bash" :]
Change the PATH variable so that /usr/lib/jvm is listed before the directory which contains Open JDK. If you are using bash, you can do this in the .bashrc file in your home directory.

Categories

Resources