Java version different from JAVA_HOME CentOS7 - java

I have a centOS7 server, and want to have JDK1.6_15 on it.
I update the /etc/profile scripts to have JAVA_HOME variable correct.
The PATH is also updated with JAVA_HOME in first place.
But, when I launch "java -version" command, I have JDK1.8 OpenJDK displayed !
When I launch the "alternatives --config java" command, I have only :
java-1.8.0-openjdk.x86_64 (/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.342.b07-1.el7_9.x86_64/jre/bin/java)
So I force things with :
alternatives --install /usr/bin/java java /opt/jdk1.6.0_15/bin/java 1
alternatives --install /usr/bin/javac javac /opt/jdk1.6.0_15/bin/javac 1
It's ok now, but, it seems not really correct to me to do this, it's weird no ?
Is there a way to install properly with yum the OpenJDK1.6 but precisely 1.6.0_15 version, not another ?

Finally, we couldn't do another way, it's the right way, so I let the things like they are

Related

No default JAVA_HOME on ubuntu 14.04

I'm trying to install tomcat7 using Ansible. After installation, when restarting service, I'm getting errors because there is no java_home set :
no JDK or JRE found - please set JAVA_HOME
I know I can set the java_home value in /etc/default/tomcat7, but what I'm looking for, is why JAVA_HOME is not set by default to the only installed Java and we have to do it manually before starting any Java application/server :
update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java Nothing to configure.
I'm using trusty 14.04 and openjdk8
Your JAVA_HOME would appear to be /usr/lib/jvm/java-8-openjdk-amd64, to set it persistently as root create /etc/profile.d/jdk.sh with
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
and make it executable,
sudo chmod 755 /etc/profile.d/jdk.sh
You need to logout and log back in for that to take effect, or you can execute
$ export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
And it should work as expected.
go to home directory and press ctrl+h and show hidden files then create .bash_aliases file into home folder.
and write two line into .bash_aliases file. /home/hadoop/install/jdk1.8.0_92 by your current jdk path. then restart terminal and check java -version, you get the version details.
export JAVA_HOME=/home/hadoop/install/jdk1.8.0_92
export PATH=$JAVA_HOME/bin:$PATH

Javac version doesn't update

I'm trying to compile a jar on my mac using 1.8 as a target release, but javac fails with the message "invalid target release".
When I run javac -version it gives me "javac 1.6.0_29".
I have the 1.8 jdk installed under "/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk", but even when I run /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/javac -version it gives me "javac 1.6.0_29".
Sym linking the CurrentJDK folder in "/System/Library/Frameworks/JavaVM.framework/Versions/" to the jdk folder in Library didn't change anything. Neither did sym linking the javac inside /usr/bin to the javac in my jdk folder.
Any ideas how to get javac to use my 1.8 version ?
Thank you very much!
UPDATE
My path variables output the following:
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/mysql/bin:/opt/X11/bin:/usr/local/git/bin:/Developer/Tools/Panda3D
echo $JAVA_HOME (since I set it already in order to get javac to work)
/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/
Preprending /Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home/bin/ to the $PATH variable didn't change the output for javac -version either.
UPDATE 2
Other question: What does javac do? Is it executing its code directly or depending on other binaries in the system? If so the link for them could be broken. Otherwise I wonder why executing the binary inside my 1.8 jdk folder gives me the version 1.6.
The proper Debian/Ubuntu way to configure which javac is pointed to by /usr/bin/javac is to use the update-alternatives command. You can do it interactively, and select from a list of available options:
sudo update-alternatives --config javac
and for java:
sudo update-alternatives --config java
In addition to what #Zakaria said, this command will show you all Java packages installed on the system, e.g.:
$ update-java-alternatives -l
java-1.7.0-openjdk-amd64 1071 /usr/lib/jvm/java-1.7.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1069 /usr/lib/jvm/java-1.8.0-openjdk-amd64
This one an overview of the Java tools and which version will be used, e.g.:
$ update-alternatives --get-selections | grep java
...
java manual /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
javac auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javac
javadoc auto /usr/lib/jvm/java-7-openjdk-amd64/bin/javadoc
...
As shown above here java would run from version 8, and javac from version 7.
If you want to update selections for all of the Java tools in one go try the following replacing the package name with one of your choice:
$ sudo update-java-alternatives -s java-1.8.0-openjdk-amd64
Verify that this has actually worked. If it didn't or partially did you have to resort to a semi-manual way, for example:
$ for i in $(update-alternatives --get-selections | grep java | awk '{system("basename "$3)}'); do sudo update-alternatives --config $i; done
where does the /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK link refer to?
Make sure it refers to the proper JDK
/Library/Java/JavaVirtualMachines/jdk{major}.{minor}.{macro[_update]}.jdk
Please check that both JAVA_HOME and PATH environment variables point to the 1.8 folder and have no link to the 1.6 java folder, especially the PATH.
Check:
echo %PATH%
Set:
export PATH="java8 folder":$PATH
or check this page: Set environment variables on Mac OS X Lion
Do the following steps
In the Windows Search bar, type "environment".
In your environment variables (account), create a variable called JAVA_HOME. Set it to C:\Program Files\Java\jdk1.8.0_65 (or wherever your JDK is).
In your system environment variables, edit PATH. Put this at the beginning of the PATH value: %JAVA_HOME%\bin;
Press OK.
Exit any command windows you are in.
Launch a command window. Type javac -version.
you should get this response: javac 1.8.0_65

Error: JAVA_HOME is not defined correctly

echo $JAVA_HOME
gives: /usr/lib/jvm/java-6-sun
but I've set /usr/lib/jvm/java-7-openjdk-amd64 in /etc/environment
source /etc/environment
gives the path I've set i.e /usr/lib/jvm/java-7-openjdk-amd64
The next time I try echo $JAVA_HOME, the wrong path is displayed.
There is probably code in /etc/profile or ~/.bashrc which sets the variable again.
Try grep -r JAVA_HOME /etc and grep JAVA_HOME ~/.??* to find places where it's used.
To avoid trouble like this, I usually create shell scripts in ~/bin/ which have the same name as the tool that I want to execute which prepare the environment.
On Ubuntu the recommended way seems to be to add the line JAVA_HOME=/usr/lib/jvm/default-java to /etc/environment and use the update-alternatives tool to manage the actual jvm.
You may have a script in /etc/profile.d/ overriding this which should be removed.
You can see which java alternatives are currently installed and available by running:
update-java-alternatives --list
To choose a jvm to use, run the following command with whatever version suits you:
update-java-alternatives --set java-1.7.0-openjdk-amd64

Gradle finds wrong JAVA_HOME even though it's correctly set

When trying to run gradle, I get the following error:
# gradle
ERROR: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/default-java
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
However, when I check the JAVA_HOME variable I get:
# echo $JAVA_HOME
/usr/lib/jvm/java-7-oracle
My JAVA_HOME is defined in .bashrc and I have double checked that it is set as the source.
Running java -version also confirms that JAVA_HOME is set correctly and is on the PATH.
# java -version
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
I have also checked that /usr/bin/java symlinks to /etc/alternatives/java which in turn correctly symlinks to /usr/lib/jvm/java-7-oracle/jre/bin/java
Additionally I've checked that there are no duplicate JAVA_HOME definitions in .bash_profile or /etc/profile.
So my question is how/why does Gradle find /usr/lib/jvm/default-java, and more importantly how do I point it to the correct directory?
Other programs which require the JDK work fine, so I think its a Gradle issue. I've also tried reinstalling Gradle which made no difference.
I'm running 64bit Xubuntu (Ubuntu 13.10 base)
Turns out that the particular Gradle binary I downloaded from the Ubuntu 13.10 repository itself tries to export JAVA_HOME. Thanks to Lucas for suggesting this.
/usr/bin/gradle line 70:
export JAVA_HOME=/usr/lib/jvm/default-java
Commenting this line out solves the problem, and Gradle finds the correct path to the Java binary.
If you just download the binary from their website it does not have this problem,
It's an issue with the Ubuntu repo version. There also seem to be some other issues with 13.10 version.
add a symbolic link
sudo ln -s /usr/lib/jvm/java-7-oracle /usr/lib/jvm/default-java
Solution is to make JAVA_HOME == dir above bin where javac lives as in
type javac
javac is /usr/bin/javac # now check if its just a symlink
ls -la /usr/bin/javac
/usr/bin/javac -> /etc/alternatives/javac # its a symlink so check again
ls -la /etc/alternatives/javac # now check if its just a symlink
/etc/alternatives/javac -> /usr/lib/jvm/java-8-openjdk-amd64/bin/javac
OK so finally found the bin above actual javac so do this
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
above can be simplified and generalized to
which javac >/dev/null 2>&1 || die "ERROR: no 'javac' command could be found in your PATH"
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which javac) )))
For me this error was due to the reason Gradle as installed as sudo and I was trying as default user to run Gradle.
Try:
sudo gradle -version
or
sudo gradle -v
In my Ubuntu, I have a headache for 2 days on this issue.
Step 1. Type on the terminal whereis java
then it will display something like this
java: /usr/bin/java /etc/java /usr/share/java /usr/lib/jvm/java-8-openjdk-amd64/bin/java /usr/share/man/man1/java.1.gz
Step 2. Take note of the path:
/usr/lib/jvm/java-8-openjdk-amd64/bin/java
exclude the bin/java
your JAVA_HOME = /usr/lib/jvm/java-8-openjdk-amd64
Did you export your JAVA_HOME? Without export, the setting will not be propagated to the commands started inside of that shell. Also, java -version does not use JAVA_HOME, rather it uses the first java found in your path. Make sure your .bashrc looks something like this:
JAVA_HOME=/path/to/java/home
export JAVA_HOME
Try installing latest version of gradle,
sudo add-apt-repository ppa:cwchien/gradle
sudo apt-get update
sudo apt-get install gradle
If we install from ubuntu repo, it will install the old version , (for me it was gradle 1.4). In older version, it sets java home from gradle as export JAVA_HOME=/usr/lib/jvm/default-java. Latest version don't have this issue.
I faced this issue when I run the following command on Ubuntu:
ionic build android
To solve this issue, I did the following steps:
ln -sf /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java /usr/lib/jvm/default-java
Add JAVA_HOME to /etc/environment:
vi /etc/environment
Add:
JAVA_HOME="/usr/lib/jvm/default-java"
After saving, read it:
source /etc/environment
Finally, you can run build command.
I had the same problem, but I didnt find export command in line 70 in gradle file for the latest version 2.13, but I understand a silly mistake there, that is following,
If you don't find line 70 with export command in gradle file in your gradle folder/bin/ , then check your ~/.bashrc, if you find export JAVA_HOME==/usr/lib/jvm/java-7-openjdk-amd64/bin/java, then remove /bin/java from this line, like JAVA_HOME==/usr/lib/jvm/java-7-openjdk-amd64, and it in path>>> instead of this export PATH=$PATH:$HOME/bin:JAVA_HOME/, it will be export PATH=$PATH:$HOME/bin:JAVA_HOME/bin/java. Then run source ~/.bashrc.
The reason is, if you check your gradle file, you will find in line 70 (if there's no export command) or in line 75,
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
That means /bin/java is already there, so it needs to be substracted from JAVA_HOME path.
That happened in my case.
I have tested this on Manjaro Linux. Should work on other Disto too.
You need to include whole java-jdk dir instead of just java/bin for java env var.
For example, instead of:
export JAVA_HOME=/opt/jdk-14.0.2/bin #change path according to your jdk location
PATH=$PATH:$JAVA_HOME
use this:
export JAVA_HOME=/opt/jdk-14.0.2/ #change path according to your jdk location
PATH=$PATH:$JAVA_HOME
then run the gradle command it will work.
You can also go to the bin folder inside your gradle installation folder and correct the JAVA_HOME parameter in gradle.bat file.
In my case, my JAVA_HOME was set to c:\Program files\java\bin
The JAVA_HOME in gradle.bat was set to %JAVA_HOME%\bin\java.exe.
I corrected the JAVA_HOME in gradle.bat and it worked.
Thank you!!!
Before running the command try entering:
export JAVA_HOME="path_to_java_home"
Where path_to_java_home is the folder where your bin/java is.
If java is properly installed you can find it's location, by using the command:
readlink -f $(which java)
Don't forget to remove bin/java from the end of the path while putting it into JAVA_HOME
For me an explicit set on the arguments section of the external tools configuration in Eclipse was the problem.
sudo ln -s /usr/lib/jvm/java-7-oracle/jre /usr/lib/jvm/default-java
Create a symbolic link to the default-java directory.
You can find your java directory by
readlink -f $(which java)
# outputs: /usr/lib/jvm/java-7-oracle/jre/bin/java
# Remove the last `/bin/java` and use it in above symbolic link command.
I had a problem with this too. It said wrong directory when it was correct. So I just created a local variable with the name of JAVA_HOME omitting the final /bin/java. It worked fine for me.
If your GRADLE_HOME and JAVA_HOME environment are set properly then check your JDK directory and make sure you have java.exe file under below path.
C:\Program Files (x86)\Java\jdk1.8.0_181\bin
As error mentioned in gradle.bat file
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
It is not able to locate your java installation. So find and set
java.exe
under %JAVA_HOME%/bin if everything is correct.
This works for me (my account got disabled by client and their admin has removed java.exe from my directory.)
[Windows] As already said, it looks like .bat -file tries to find java.exe from %JAVA_HOME%/bin/java.exe so it doesn't find it since bin is repeated twice in path.
Remov that extra /bin from gradle.bat.
In my dockercontainer (being minimal the problem of not finding java) was, that "which" was not installed. Comipling a project using gradlew used which in ./gradlew to find java
Installing which solved the problem.
Adding below lines in build.gradle solved my issue .
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
#ISSUE:GradleException: javaConfig.targetVersion is Java 8, but the environment variable JAVA8_HOME does not exist
I think this is how you fix it in IntelliJ. I've run into it a couple times as I choose "Launch in New Window" for a new project but I haven't written down the steps yet.
1.File -> Project Structure. Project Settings / Project. Make sure Project SDK and Project language level are correct.
2.Preferences. Build, Execution, Deployment / Build Tools / Gradle. Make sure Gradle JVM is correct.
You may have to restart IntelliJ after this.
NOW it SOLVED THE ISSUE
Task :prepareKotlinBuildScriptModel UP-TO-DATE
Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
See https://docs.gradle.org/7.3.3/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 22s

JAVA_HOME environment variable not set Validator.nu HTML Parser

I am trying to install a local version of the Validator.nu server and it keeps failing on trying to build the HTML Parser.
It says it can't find the JAVA_HOME variable which I have set in my .bashrc file and shows correctly when I type "echo $JAVA_HOME" at the prompt
Ideas appreciated thanks
Error output
"hg" pull --update -R build https://bitbucket.org/validator/build/
Not trusting file build/.hg/hgrc from untrusted user dave, group dave
Not trusting file /home/dave/src/checker/build/.hg/hgrc from untrusted user dave, group dave
warning: bitbucket.org certificate with fingerprint 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe not verified (check hostfingerprints or web.cacerts config setting)
pulling from https://bitbucket.org/validator/build/
warning: bitbucket.org certificate with fingerprint 81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe not verified (check hostfingerprints or web.cacerts config setting)
searching for changes
no changes found
Error: The JAVA_HOME environment variable is not set.
Set the JAVA_HOME environment variable to the pathname of the directory where your JDK is installed.
Instead of:
$ sudo python build/build.py all
try:
$ sudo -E python build/build.py all
The sudo command for security reasons resets the environment (so your JAVA_HOME for the python process is wiped out even when it's exported). The "sudo -E" will preserve the environment.
I assume (from tag) you use ubuntu.
list versions of installed javas in your system:
dave#ubuntu:~$ update-java-alternatives --list
java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
Note, that if you set JAVA_HOME in ~/.bashrc it will be set only in your terminal sessions.
Unless you export it, it will be set only for your current shell process (not subprocesses like mercurial).
add line to your .bashrc:
export JAVA_HOME="/usr/lib/jvm/java-6-openjdk"
open a new terminal and test it:
$JAVA_HOME/bin/java -version && echo java seen by bash
bash -c '$JAVA_HOME/bin/java -version && echo java seen by bash subprocesses'
If you want to set environment for all processes (not only started by hand from terminal), you can:
dave#ubuntu:~$ sudo $EDITOR /etc/environment
After tackling this for the last 4 days I have managed to get the validator.nu server running on my local Ubuntu VM and so I thought I would update this thread in case anyone else runs in to the same issues.
I am still not 100% sure where the original issue with the JAVA_HOME variable was coming from but I suspect (although I am not an expert at this) that it had something to do with the way I was using sudo to run the python build.
I was initially following the instructions on http://about.validator.nu/#src but using
$ sudo python build/build.py all
This was because part of the build needed the correct permissions to work.
This is my step-by-step process which starts from a clean install of Ubuntu 11.
installed ubuntu 11
opened the terminal
sudo /bin/bash <----------- I THINK THIS IS THE CRUCIAL LINE
apt-get install mercurial
apt-get install subversion
apt-get install openjdk-6-jre
apt-get install openjdk-6-jdk
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk
follow rest of http://about.validator.nu/#src instructions
I'm going to need to do it again when I set this up for the internal network for our build scripts so i'll edit this if I've missed out on anything.
Hope this saves another person's headache and lost days!

Categories

Resources