I have an Amazon EC2 t3.medium instance on Linux.
I am trying to run Apache ni-fi on this instance and I need java.
When I check the JAVA_HOME default:
$ echo$JAVA_HOME
-bash: echo/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.261-2.6.22.2.amzn2.0.2.x86_64: No such file or directory
Then, I downloaded java 1.8 by the following comamnds on terminal:
$ sudo yum install java-1.8.0-openjdk.x86_64
$ sudo update-alternatives --config java
(I selected 2 for java 1.8)
To find the location of my java file, I run them:
$ file $(which java)
/usr/bin/java: symbolic link to `/etc/alternatives/java'
$ file /etc/alternatives/java
/etc/alternatives/java: symbolic link to `/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java'
$ file /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java
/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 3.2.0, BuildID[sha1]=1b1c0fd721197a04f9bfc9b0891f1bd83a5f49d5, not stripped
I guess it is working properly. Then, I change JAVA_HOME from 1.7 to 1.8 by writing these commands on terminal for both ec2-user and root:
[root#ip-178-32-11-247 ~]# export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64"
[root#ip-178-32-11-247 ~]# PATH=$JAVA_HOME/bin:$PATH
In advance, I have setup nifi on root. And in nifi-1.16.0 directory, I am trying to run this command:
[root#ip-178-32-11-247 nifi-1.16.0]# bin/nifi.sh start
The Error message is:
Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64
NiFi home: /root/nifi-1.16.0
Bootstrap Config File: /root/nifi-1.16.0/conf/bootstrap.conf
bin/nifi.sh: line 401: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/bin/java: No such file or directory
I thought that java is working but JAVA_HOME couldn't setup properly but I couldn't solve that. What should I do at that point to solve the problem and start nifi?
I will be appreciated very much if you can help, I coludn't start my term project because of this error :(
The correct path for JAVA_HOME should be /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java
export JAVA_HOME="/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.312.b07-1.amzn2.0.2.x86_64/jre/bin/java"
But probably you don't need to export JAVA_HOME anyway. You should have a link in /usr/bin/. You can check this by doing the following:
[ssm-user#ip-172-31-85-243 bin]$ which java
/usr/bin/java
By default Apache Nifi is using the executable /usr/bin/java, so you don't need to export JAVA_HOME.
I'm trying to run the .net core sonarscanner tool on Jenkins (running on Linux) like:
dotnet sonarscanner begin ...
But it's giving the error
Could not find 'java' executable in JAVA_HOME or PATH.
I'm not sure why this is as I am explicitly setting the path at the top of my pipeline:
environment {
JAVA_HOME="${tool 'openjdk-11'}/jdk-11"
PATH="${tool 'openjdk-11'}/jdk-11/bin:$HOME/.dotnet/tools/:$PATH"
}
And from running the following commands I can see this looks correct:
sh "echo \"Java Home:\" $JAVA_HOME"
Produces:
Java Home: /var/lib/jenkins/tools/hudson.model.JDK/openjdk-11
And listing the directory:
sh "ls /var/lib/jenkins/tools/hudson.model.JDK/openjdk-11/jdk-11/bin"
produces:
+ ls /var/lib/jenkins/tools/hudson.model.JDK/openjdk-11/jdk-11/bin
jaotc
jar
jarsigner
java
javac
javadoc
javap
jcmd
jconsole
jdb
jdeprscan
jdeps
jhsdb
jimage
jinfo
jjs
jlink
jmap
jmod
jps
jrunscript
jshell
jstack
jstat
jstatd
keytool
pack200
rmic
rmid
rmiregistry
serialver
unpack200
Yet still, sonar scanner fails with the error:
Could not find 'java' executable in JAVA_HOME or PATH.
UPDATE:
Regarding Dimitry's comment - I am using the tools:
With this at the top of the pipeline:
tools{
jdk 'openjdk-11'
}
With regards to Marcinek's answer - good spot. I've realised that setting the JAVA_HOME at the top of the pipeline is not actually doing anything. Whatever I set it to, it remains as:
/var/lib/jenkins/tools/hudson.model.JDK/openjdk-11
The variable $JAVA_HOME should point to the main directory of java, where the bin folder can be found by appending bin
Your $JAVA_HOME variable is pointing to
Java Home: /var/lib/jenkins/tools/hudson.model.JDK/openjdk-11
To find the java executable you have to append jdk-11/bin
Thus the correct path to JAVA_HOME should be:
/var/lib/jenkins/tools/hudson.model.JDK/openjdk-11/jdk-11
And the PATH should point to:
/var/lib/jenkins/tools/hudson.model.JDK/openjdk-11/jdk-11/bin
You can use 'tools' section to use java in your pipeline.
pipeline {
agent any
tools {
jdk 'your-jdk-tool-name'
}
Not working in Windows 10:
> jar xf file.jar
'jar' is not recognized as an internal or external command, operable program or batch file.
In a PowerShell, you should first:
$Env:Path+="C:\Program Files (x86)\Java\jre1.8.0_181\bin"
Change jre1.8.0_181 according to your installed Java Runtime Environment. For sanity check, you can print the updated path:
$Env:Path
Then:
java -jar -h
I still haven't figured how to get the xf subcommand to work though.
Set the JAVA_HOME in Environment variable.
Then set path.
then open a new Command prompt and type
$ javac -version
It should print something like that
javac 1.8.0_152
Now try
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I'm ssh'd into my server (Ubuntu 12.04) and no matter what I set for JAVA_HOME and JRE_HOME tomcat6 doesn't want to start:
me#myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ echo $JAVA_HOME
/usr/lib/jvm/jdk-oracle.1.6.0_33/bin
me#myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ echo $JRE_HOME
/usr/lib/jvm/jdk-oracle.1.6.0_33/jre
me#myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ sudo service tomcat6 start
* no JDK found - please set JAVA_HOME
me#myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ export JAVA_HOME=/usr/lib/jvm/jdk-oracle.1.6.0_33
me#myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ sudo service tomcat6 start
* no JDK found - please set JAVA_HOME
me#myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ ls $JAVA_HOME
bin db jre LICENSE README.html register_ja.html src.zip
COPYRIGHT include lib man register.html register_zh_CN.html THIRDPARTYLICENSEREADME.txt
me#myserver:/usr/lib/jvm/jdk-oracle.1.6.0_33$ ls $JAVA_HOME/bin
appletviewer HtmlConverter java javap jdb jps jstat native2ascii rmic serialver wsgen
apt idlj javac javaws jhat jrunscript jstatd orbd rmid servertool wsimport
ControlPanel jar javadoc jconsole jinfo jsadebugd jvisualvm pack200 rmiregistry tnameserv xjc
extcheck jarsigner javah jcontrol jmap jstack keytool policytool schemagen unpack200
I was looking at tomcat6's init.d script, and I found some custom logic that searches for openjdk. I don't want to use openjdk, I purposely installed oracle! Here's a snippit of the init.d script (which I didn't write):
# this is a work-around until there is a suitable runtime replacement
# for dpkg-architecture for arch:all packages
# this function sets the variable OPENJDKS
find_openjdks()
{
for jvmdir in /usr/lib/jvm/java-7-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-7-openjdk-common" ]
then
OPENJDKS=$jvmdir
fi
done
for jvmdir in /usr/lib/jvm/java-6-openjdk-*
do
if [ -d "${jvmdir}" -a "${jvmdir}" != "/usr/lib/jvm/java-6-openjdk-common" ]
then
OPENJDKS="${OPENJDKS} ${jvmdir}"
fi
done
}
# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in $DEFAULT)
OPENJDKS=""
find_openjdks
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm"
# Look for the right JVM to use
for jdir in $JDK_DIRS; do
if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
JAVA_HOME="$jdir"
fi
done
export JAVA_HOME
I had to remove the openjdk from /usr/lib/jvm because stupid tomcat kept finding it and using it, even though my JAVA_HOME variable was set to use oracle's java.
Help please? I have no idea how to fix this. I'm using maven and maven works perfectly fine with the way i've set the JAVA_HOME variable.
Edit:
I opened the init.d tomcat script and changed this line:
JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm"
to this:
JDK_DIRS="/usr/lib/jvm/jdk-oracle.1.6.0_33 /usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm"
(I just added my path /usr/lib/jvm/jdk-oracle.1.6.0_33 to the string)
And suddenly tomcat booted and ran with my oracle java. I guess this works, but that can't have been the best way to do it.
Edit:
StephenC:
me#myserver:/usr/lib/jvm$ sudo bash
root#myserver:/usr/lib/jvm# echo $JAVA_HOME
/usr/lib/jvm/jdk-oracle.1.6.0_33
Try this:
sudo bash
echo $JAVA_HOME
I suspect that the problem is that your $JAVA_HOME environment variable is not being passed through sudo to the command it is running. The manual entry certainly implies that it won't be!! (Your experiment seems to imply otherwise, but I suspect that something else is confusing things ...)
I'm not sure what the best long-term fix for this, but the alternatives include:
Setting $JAVA_HOME in the catalina.sh script
Setting $JAVA_HOME in the tomcat init.d script
Some distros have a convention that all distro-provided service launch scripts pick up local config overrides from a file in /etc ...
Setting $JAVA_HOME in the shell RC file for the "tomcat" user (probably a bad idea)
Tweaking the sudoers config so that $JAVA_HOME is passed (definitely a bad idea!)
Using the "-E" option ...
IMO, it is a bad idea to rely on your $JAVA_HOME environment variable when launching a service. The chances are that you will forget and launch with the wrong JDK by mistake. Protect yourself.
I am using Linux Mint Cinnamon 14. I have set the $JAVA_HOME and $PATH environment variables in ~/.profile as follows:
export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=/home/aqeel/development/jdk/jdk1.6.0_35/bin:$PATH
I then did source ~/.profile to make the proper changes.
When I execute java -version command to check the active java version, it shows the default (already installed open-jdk) java version. How can I override the default open-jdk with the one I downloaded?
UPDATE:
which java says /usr/bin/java
$JAVA_HOME/bin/java -version says 'Permission Denied'
sudo $JAVA_HOME/bin/java -version (asks for password, then) says Command not found
but cd $JAVA_HOME/bin, and ls shows that it is right directory.
While it looks like your setup is correct, there are a few things to check:
The output of env - specifically PATH.
command -v java tells you what?
Is there a java executable in $JAVA_HOME\bin and does it have the execute bit set? If not chmod a+x java it.
I trust you have source'd your .profile after adding/changing the JAVA_HOME and PATH?
Also, you can help yourself in future maintenance of your JDK installation by writing this instead:
export JAVA_HOME=/home/aqeel/development/jdk/jdk1.6.0_35
export PATH=$JAVA_HOME/bin:$PATH
Then you only need to update one env variable when you setup the JDK installation.
Finally, you may need to run hash -r to clear the Bash program cache. Other shells may need a similar command.
Cheers,
update-java-alternatives
The java executable is not found with your JAVA_HOME, it only depends on your PATH.
update-java-alternatives is a good way to manage it for the entire system is through:
update-java-alternatives -l
Sample output:
java-7-oracle 1 /usr/lib/jvm/java-7-oracle
java-8-oracle 2 /usr/lib/jvm/java-8-oracle
Choose one of the alternatives:
sudo update-java-alternatives -s java-7-oracle
Like update-alternatives, it works through symlink management. The advantage is that is manages symlinks to all the Java utilities at once: javac, java, javap, etc.
I am yet to see a JAVA_HOME effect on the JDK. So far, I have only seen it used in third-party tools, e.g. Maven.
If you want to use JDKs downloaded from Oracle's site, what worked for me (using Mint) is using update-alternatives:
I downloaded the JDK and extracted it just anywhere, for example in /home/aqeel/development/jdk/jdk1.6.0_35
I ran:
sudo update-alternatives --install /usr/bin/java java /home/aqeel/development/jdk/jdk1.6.0_35/bin/java 1
Now you can execute sudo update-alternatives --config java and choose your java version.
This doesn't set the JAVA_HOME variable, which I wanted configured, so I just added it to my ~/.bashrc, including an export JAVA_HOME="/home/aqeel/development/jdk/jdk1.6.0_35" statement
Now, I had two JDKs downloaded (let's say the second has been extracted to /home/aqeel/development/jdk/jdk-10.0.1).
How can we change the JAVA_HOME dynamically based on the current java being used?
My solution is not very elegant, I'm pretty sure there are better options out there, but anyway:
To change the JAVA_HOME dynamically based on the chosen java alternative, I added this snippet to the ~/.bashrc:
export JAVA_HOME=$(update-alternatives --query java | grep Value: | awk -F'Value: ' '{print $2}' | awk -F'/bin/java' '{print $1}')
Finally (this is out of the scope) if you have to change the java version constantly, you might want to consider:
Adding an alias to your ~./bash_aliases:
alias change-java="sudo update-alternatives --config java"
(You might have to create the file and maybe uncomment the section related to this in ~/.bashrc)
$JAVA_HOME/bin/java -version says 'Permission Denied'
If you cannot access or run code, it which be ignored if added to your path. You need to make it accessible and runnable or get a copy of your own.
Do an
ls -ld $JAVA_HOME $JAVA_HOME/bin $JAVA_HOME/bin/java
to see why you cannot access or run this program,.
When it searches for java it looks from left to right in path entries which are separated by : so you need to add the path of latest jdk/bin directory before /usr/bin, so when it searches it'll find the latest one and stop searching further.
i.e. PATH=/usr/java/jdk_1.8/bin:/usr/bin:..... and so on.
then initialize user profile using command: source ~/.bash_profile
and check with: [which java]
you'll get the right one.
check available Java versions on your Linux system by using update-alternatives command:
$ sudo update-alternatives --display java
Now that there are suitable candidates to change to, you can switch the default Java version among available Java JREs by running the following command:
$ sudo update-alternatives --config java
When prompted, select the Java version you would like to use.1 or 2 or 3 or etc..
Now you can verify the default Java version changed as follows.
$ java -version
Try this:
export JAVA_HOME=put_here_your_java_home_path
type export PATH=$JAVA_HOME/bin:$PATH (ensure that $JAVA_HOME is the first element in PATH)
try java -version
Reason: there could be other PATH elements point to alternative java home. If you put first your preferred JAVA_HOME, the system will use this one.
There is an easy way, just remove the symbolic link from "/usr/bin". It will work.
Updating the ~/.profile or ~/.bash_profile does not work sometimes. I just deleted JDK 6 and sourced .bash_profile.
Try running this:
sudo rm -rd jdk1.6.0_* #it may not let you delete without sudo
Then, modify/add your JAVA_HOME and PATH variables.
source ~/.bash_profile #assuming you've updated $JAVA_HOME and $PATH
In Linux Mint 18 Cinnamon be sure to check /etc/profile.d/jdk_home.sh I renamed this file to jdk_home.sh.old and now my path does not keep getting overridden and I can call java -version and see Java 9 as expected. Even though I correctly selected Java 9 in update-aternatives --config java this jdk_home.sh file kept overriding the $PATH on boot-up.