Java JPS tool not working - java

I am trying to use the JPS tool (Java Process Monitoring Tool)
I have Oracle jdk1.6 on my ubuntu-12.04 machine
My Configuration.
$ java -version
java version "1.6.0_39"
Java(TM) SE Runtime Environment (build 1.6.0_39-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01, mixed mode)
$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/bin:/usr/bin/java:/usr/lib/jvm/jdk1.6.0_39
$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
JAVA_HOME="/usr/lib/jvm/jdk1.6.0_39"
$ jps
The program 'jps' can be found in the following packages:
* openjdk-6-jdk
* openjdk-7-jdk
Try: sudo apt-get install <selected package>
I want to use oracle-jdk not open-jdk.

use this command
export PATH=$PATH:/usr/lib/jvm/jdk1.6.0_39/bin
And then try jps command in the same shell.

If you have exported the java/bin path in your .bashrc, then try to reload the .bashrc file
type
$> cd $HOME
$> . .bashrc
and then try to echo the Path. It should include the java/bin folder.
$> echo $PATH
it should solve the problem

I have the same problems like yours. At first I have had Java 1.7 installed on my machine, then I installed Java 1.6.
When I check inside this folder, I found no jps
/usr/lib/jvm/java-6-openjdk-i386/bin
So I uninstall Java 1.7 (through Synaptic Package Manager), and re-install Java 1.6 again. After that, I can see jps inside /usr/lib/jvm/java-6-openjdk-i386/bin folder. And I can use jps again.
I hope that it'll help. This is my first answer in Stack Overflow, so please do not vote down.

I solved it by adding a shell alias in /etc/profile after environment variables:
alias jps='/usr/jdk/bin/jps'
it works now.

Related

How can I set classpath in Mac Os for Selenium webdriver [duplicate]

Java is an optional package on the latest versions of macOS.
Yet once installed it appears like the JAVA_HOME environment variable is not set properly.
With the Java optional package or Oracle JDK installed,
adding one of the following lines to your ~/.bash_profile file will set the environment variable accordingly.
export JAVA_HOME="$(/usr/libexec/java_home -v 1.6)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.7)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
or simply
export JAVA_HOME="$(/usr/libexec/java_home)"
Note: If you installed openjdk on mac using brew, run sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk for the above to work
Update: added -v flag based on Jilles van Gurp response.
/usr/libexec/java_home is not a directory but an executable. It outputs the currently configured JAVA_HOME and doesn't actually change it. That's what the Java Preferences app is for, which in my case seems broken and doesn't actually change the JVM correctly. It does list the 1.7 JVM but I can toggle/untoggle & drag and drop all I want there without actually changing the output of /usr/libexec/java_home.
Even after installing 1.7.0 u6 from Oracle on Lion and setting it as the default in the preferences, it still returned the apple 1.6 java home. The only fix that actually works for me is setting JAVA_HOME manually:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home/
At least this way when run from the command line it will use 1.7. /usr/libexec/java_home still insists on 1.6.
Update: Understanding Java From Command Line on OSX has a better explanation on how this works.
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
is the way to do it. Note, updating this to 1.8 works just fine.
For me, Mountain Lion 10.8.2, the solution most voted does not work.
I installed jdk 1.7 via Oracle and maven from homebrew.
My solution is from the hadoop-env.sh file of hadoop which I installed from homebrew, too.
I add the below sentence in ~/.bash_profile, and it works.
export JAVA_HOME="$(/usr/libexec/java_home)"
This solution also works for OS X Yosemite with Java 1.8 installed from Oracle.
None of the above answers helped me. I suppose all the answers are for older OS X
For OS X Yosemite 10.10, follow these steps
Use your favorite text editor to open: ~/.bash_profile
//This command will open the file using vim
$ vim ~/.bash_profile
Add the following line in the file and save it ( : followed by "x" for vim):
export JAVA_HOME=$(/usr/libexec/java_home)
Then in the terminal type the following two commands to see output:
$ source ~/.bash_profile
$ echo $JAVA_HOME
In the second line, you are updating the contents of .bash_profile file.
Update for Java 9 and some neat aliases.
In .bash_profile:
export JAVA_HOME8=`/usr/libexec/java_home --version 1.8`
export JAVA_HOME9=`/usr/libexec/java_home --version 9`
Note, that for the latest version it is 9 and not 1.9.
Set active Java:
export JAVA_HOME=$JAVA_HOME8
export PATH=$JAVA_HOME/bin:$PATH
Some additional alias to switch between the different versions:
alias j8='export JAVA_HOME=$JAVA_HOME8; export PATH=$JAVA_HOME/bin:$PATH'
alias j9='export JAVA_HOME=$JAVA_HOME9; export PATH=$JAVA_HOME/bin:$PATH'
Test in terminal:
% j8
% java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
% j9
% java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
EDIT: Update for Java 10
export JAVA_HOME10=`/usr/libexec/java_home --version 10`
alias j10='export JAVA_HOME=$JAVA_HOME10; export PATH=$JAVA_HOME/bin:$PATH'
EDIT: Update for Java 11
export JAVA_HOME11=`/usr/libexec/java_home --version 11`
alias j11='export JAVA_HOME=$JAVA_HOME11; export PATH=$JAVA_HOME/bin:$PATH'
The above didn't work for me with Amazon's EC2 tools, because it expects bin/java etc. underneath JAVA_HOME. /System/Library/Frameworks/JavaVM.framework/Home did work.
For OS X you can do:
export JAVA_HOME=`/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home`
On Mac OS X Lion, to set visualgc to run, I used:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
The following worked for me. I'm using ZSH on OSX Yosemite with Java 8 installed.
The following command /usr/libexec/java_home emits the path to JDK home:
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
In your ~/.zshrc,
export JAVA_HOME = "/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home"
for macOS Mojave 10.14.1 and JAVA 11.0.1
I set the profile as
export JAVA_HOME=$(/usr/libexec/java_home)
key in terminal this to confirm:
$JAVA_HOME/bin/java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
A better (more upgradable) way is to use the following:
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
This should work with AWS also since it has bin underneath Home
Newer Oracle JVMs such as 1.7.0_21-b12 seem to install here:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
My approach is:
.bashrc
export JAVA6_HOME=`/usr/libexec/java_home -v 1.6`
export JAVA7_HOME=`/usr/libexec/java_home -v 1.7`
export JAVA_HOME=$JAVA6_HOME
# -- optional
# export PATH=$JAVA_HOME/bin:$PATH
This makes it very easy to switch between J6 and J7
I Had to explicitly set it to the exact path on my Macbook air .
Steps followed:
try to echo $JAVA_HOME (if it's set it'll show the path), if not, try to search for it using sudo find /usr/ -name *jdk
Edit the Bash p with - sudo nano ~/.bash_profile
Add the exact path to JAVA Home (with the path from step 2 above)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
Save and exit
Check JAVA_Home using - echo $JAVA_HOME
I am running MACOS MOJAVE - 10.14.2 (18C54) on a Macbook Air with JAVA 8
OSX Yosemite, ZSH, and Java SE Runtime Environment 8, I had to:
$ sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands /System/Library/Frameworks/JavaVM.framework/Versions/Current/bin
and in ~/.zshrc change JAVA_HOME to
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/Current"
For Mac OS X 10.9 I installed the latest version of JRE from Oracle and then reset the JAVA_HOME to /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home.
I am sure there is a better way but this got me up and running.
hughsmac:~ hbrien$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
For Java 11 (JDK 11) it can be located with the following command:
/usr/libexec/java_home -v 11
Got the same issue after I upgrade my Mac OS and following worked for me:
cmd>vi ~/.bash_profile
Add/update the line for JAVA_HOME:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk/Contents/Home"
cmd>source ~/.bash_profile or open a new terminal
I think the jdk version might differ, so just use the version which you have under /Library/Java/JavaVirtualMachines/
If you are in need to have multiple versions of JDK under Mac OS X (Yosemite), it might be helpful to add some scripting for automated switching between them.
What you do is to edit your ~/.bash_profile and add the following:
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $#`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
setjdk 1.7
What the script does is to first remove other JDK versions in the PATH so that they won’t interfere with our new JDK version. Then it makes some clever use of /usr/libexec/java_home which is a command that lists installed JDK versions. The -v argument tells java_home to return the path of the JDK with the supplied version, for example 1.7. We also update the PATH to point to the bin directory of the newly found JAVA_HOME directory. At the end we can simply execute the function using
setjdk 1.7
which selects the latest installed JDK version of the 1.7 branch. To select a specific version you can simply execute
setjdk 1.7.0_51
instead. Run /usr/libexec/java_home -V to get more details on how to choose versions.
P.S. Do not forget to source ~/.bash_profile after you save it.
For Fish terminal users on Mac (I believe it's available on Linux as well), this should work:
set -Ux JAVA_8 (/usr/libexec/java_home --version 1.8)
set -Ux JAVA_12 (/usr/libexec/java_home --version 12)
set -Ux JAVA_HOME $JAVA_8 //or whichever version you want as default
This answer is related to Mountain Lion and not Lion. I needed to do this for the AWS Command Line Tools. According to the AWS docs, running which java returns /usr/bin/java.
So, I set JAVA_HOME=/usr in my .bashrc.
Apparently, /usr/bin/java is a symbolic link to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java which makes it all work.
Update
As mentioned in the comment below, this JAVA_HOME value is not an ideal solution when the JAVA_HOME environment variable is to be used by things other than the AWS Command Line Tools. It works fine for the AWS Command Line Tools, though, as given in their docs.
for mac user .
java 8 should add
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
# JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
java 6 :
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
# JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
ref :http://qiita.com/seri_k/items/e978c1339ce51f13e297
For Mac Yosemite,
JDK 1.7.0_xx is using
$ ls -ltar /usr/bin/java
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_xx.jdk/Contents/Home
Anyone using AUSKEY from the Australian Tax Office (ATO) should uninstall AUSKEY.
This sorted out my JAVA_HOME issues.
It is also no longer required for MAC users. Yah!
I'm using Fish shell on High Sierra 10.13.4 and installed Java via Brew.
It's not automatically set up so to set it correctly on my system I run:
set -U JAVA_HOME (/usr/libexec/java_home)
Just set java_home of 1.8 jdk version in netbeans.conf file:
/Applications/NetBeans/NetBeans 8.2.app/Contents/Resources/NetBeans/etc/netbeans.conf
uncomment line:
netbeans_jdkhome="path/to/jdk"
and set path to your 1.8 jdk, in my case:
netbeans_jdkhome="/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home"
This approach lays you to have several jdk versions on mac os
Handy command for knowing java home and other details.
java -XshowSettings:properties -version
and to know all java homes on your mac:
/usr/libexec/java_home -V

JRE error when trying to install Matlab Compiler Runtime

Once again, I spent much time trying to get something to work without success.
I want to install MATLAB Compiler Runtime on my Ubuntu 13.04, where there is no MATLAB installed.
Here's what I did:
I downloaded the 64-bit Linux version R2012b(8.0) off of
http://www.mathworks.com/products/compiler/mcr/index.html?s_cid=BB.
Then, I switched into the folder and tried to install via
sudo ./install just to receive the following message:
Error: Cannot locate Java Runtime Environment (JRE).
The directory /home/konni/Downloads/MCR_R2012b_glnxa64_installer/sys/java/jre/glnx86/jre does not exist.
And, it does not exist indeed, but there exists a folder with "glnxa86" instead of "glnx86". I wouldn't just want to rename it, though.
I do have a JRE installed on my machine, btw:
java version "1.7.0_25"
OpenJDK Runtime Environment (IcedTea 2.3.10) (7u25-2.3.10-1ubuntu0.13.04.2)
OpenJDK Server VM (build 23.7-b01, mixed mode)
I have absolutely no clue what to do. The problems I found using google didn't quite help me, either...
Maybe you have an idea?
I'd greatly appreciate any help! :-)
If the only problem is finding the JRE, then the command line switch -javadir will get you done:
./install -javadir /usr/lib/jvm/java-7-openjdk-i386/jre/
I had the same problem recently when installing a software that required a 7.13 MCR on an Ubuntu 17.10.
In this
https://www.linuxquestions.org/questions/linux-newbie-8/matlab-7-5-compiled-runtime-for-64-bit-linux-installation-no-jre-error-838281/
I found that the 32 bit version installs fine, and it did, but obviously, that didn't solve my problem.
However, I found a way to do it. The trick is that the installer needs the old JRE (1.5) and will not work with JDK 8.
So the first step is to run
./MCRInstaller.bin -is:extract
this will create a directory called istemp... something, for me istemp23732345211606.
ls
jre1.5.0-linux-amd64.bin JVMNotFound.txt setup.jar Verify.jar
It is tempting to run the setup.jar directly, do try, but with Java 8, I only got the following error message:
Could not load wizard specified in /wizard.inf (104)
But perhaps it will work for you. People who get the above mentioned error with wizard.inf should look further, because the installer needs JDK 5 to run.
I chose not to use the bundled version but downloaded the JDK 5 from Oracle. The bundled version might work as well - I did not try.
You can download JDK 5 from here:
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html#jdk-1.5.0_22-oth-JPR
Extract the downloaded archive (chmod +x the bin and run), then copy the files to /usr/lib/jvm/java5
Rename the jdk1.5.0_022 or anything to jdk1.5.0 to make it simple.
Fix attributes:
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws
sudo chown -R root:root /usr/lib/jvm/java5/jdk1.5.0
Then run:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/java5/jdk1.5.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java5/jdk1.5.0/bin/javac" 1
Now chose the jdk 5 as default
sudo update-alternatives --config java
And selecting the appropriate option.
Check that it worked
java -version
You should see something like this:
java version "1.5.0_22" Java(TM) 2 Runtime Environment, Standard
Edition (build 1.5.0_22-b03) Java HotSpot(TM) 64-Bit Server VM (build
1.5.0_22-b03, mixed mode)
Now you can run the setup.jar file in the extracted directory (istemp...)
sudo java -jar setup.jar
I recommend that you chose a contemporary java by running
sudo update-alternatives --config java
again.
When running the installer.sh, use the command line option "-is:javahome [path to your java jre folder]".
For instance, I installed below a java 8 jre on an old matlab compiler 2007b as follow:
sudo /opt/installer.sh -console -is:javahome /usr/lib/jvm/java-8-openjdk-amd64/jre/
I had same problem. The problem is you are installing 64-bit matlab on 32-bit ubuntu. use 32-bit matlab and install in ubuntu 32-bit. use 64-bit matlab and install in ubuntu 64-bit. Please like the answer if it was helpful.

Maven with Cygwin - Error: JAVA_HOME is not defined correctly

I'm trying to run Maven on cygwin. I've added maven to the path and my Java home looks like this:
$ echo $JAVA_HOME
/cygdrive/c/Program Files/Java/jdk1.6.0
Yet when I try to run mvn --version, I get this:
Error: JAVA_HOME is not defined correctly.
We cannot execute /cygdrive/c/Program Files/Java/jdk1.7.0_01/bin/java
Any idea why it's not working? Java -version works fine, so it's not a problem with java. I've also tried jdk1.6.0 instead.
Running which java gives,
$ which java
/cygdrive/c/windows/system32/java
and java -version gives,
$ java -version
java version "1.7.0_01"
Java(TM) SE Runtime Environment (build 1.7.0_01-b08)
Java HotSpot(TM) Client VM (build 21.1-b02, mixed mode, sharing)
If I run mvn.bat instead of mvn, I didn't have this problem.
So, since Cygwin will run the mvn file, I replaced this mvn file with a softlink (ln -s mvn.bat mvn) to the batch file. This way, running mvn will silently run the mvn.bat which handles these problems gracefully.
Anyone Using Cygwin and Maven, here's exactly what you need:
In your Cygwin bash prompt:
$ vim ~/.bashrc
or:
$ nano ~/.bashrc
(Which ever you fancy...)
Append the following:
alias mvn=mvn.bat
Save and Exit. Then run:
$ source ~/.bashrc
Now you should be able to use the mvn command as you do in cmd prompt.
Cygwin uses a dos console to execute Maven builds (mvn.bat).
Set your Java home to the C:\Program Files\Java\jdk1.7.0_01 location.
I was facing the same problem while running gradle from cygwin tool.
I used to set the Java home including the bin folder:
C:\Program Files\Java\jdk1.7.0_67\bin
But later I realized that some application do not recognize if you include bin folder, so I changed the class path to C:\Program Files\Java\jdk1.7.0_67 and it started working.
Setting JAVA_HOME to /cygdrive/c/Progra~1/Java/jdk1.6.0 might help.

Hadoop : JPS can not find Java installed

my configurations are
hduser#worker1:/usr/local/hadoop/conf$ jps
The program 'jps' can be found in the following packages:
* openjdk-6-jdk
* openjdk-7-jdk
Ask your administrator to install one of them
I have java installed though
hduser#worker1:/usr/local/hadoop/conf$ java -version
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre10-0ubuntu5)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)
hduser#worker1:/usr/local/hadoop/conf$ echo $JAVA_HOME
/usr/lib/jvm/java-1.6.0-openjdk
and also set up in conf/hadoop-env.sh
hduser#worker1:/usr/local/hadoop/conf$ cat hadoop-env.sh | grep JAVA_HOME
# The only required environment variable is JAVA_HOME. All others are
# set JAVA_HOME in this file, so that it is correctly defined on
export JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk
How can I make JPS work?
Saurabh Saxena's answer above is no longer correct.
To get jps, you want to also install the development tools java-1.6.0-openjdk-devel.
On CentOS 6 the file is:
java-1.6.0-openjdk-devel.x86_64
So:
yum install java-1.6.0-openjdk*
will do the trick (also picks up demo and javadocs besides the jdk and dev tools, but you will get the full complement of command line tools).
For Ubuntu:
apt-get install java-1.6.0-openjdk-devel
For all these examples, you can try JDK7 (just substitute 1.7), and as of December 2012, Hadoop is pretty stable without the Oracle libraries. See: http://openjdk.java.net/install/
This might also be a reason. Its simple: See if $javac works. Note: $java might work, check javac. If $javac is not working then $jps will not work either.
So you might want to do something like
export PATH=$PATH:$JAVA_HOME/bin
and try again. both javac and jps.
good luck.
I have found the solution for the missing JPS command. I was installing Hadoop 1.x on ubuntu machine in a pseudo distributed mode. I used Java-7-openJDK to provide for the Java commands and tools. For some reason there was a java-1.6.0-openjdk-devel for version 6 but none for version 7 specifically debian and ubuntu distributions. I am not sure if the same is true for Fedora and Redhat. So the best answer as that time was using the linux command
ps -aux | grep java
I hated doing that because Hadoop daemons start with so many options that each result fills up more than a screen. Apart from seeing that java is running it is impossible to see what hadoop daemons are running. Hence i came up with a short soultion in the form of one line shell script
This is my JPS scirpt for open JDK
!#/bin/bash
ps -aux | grep java | awk '{print $12}'
END
I saved these two lines in a file named jps and stored it in the hadoop/bin directory with execute permissions
**Here is the result of the script
hduser#localhsot# ./jps
-Dproc-namenode
-Dproc-datanode
-Dproc-JobTracker
-Dproc-TaskTracker**
It seems like open-jdk does not have jps in it.
For hadoop, installing sun-jvm would be a better choice.
try this....
sudo apt-get install openjdk-7-jdk
I would like to update topic for those who would face the same problem.
JDK8 also does not have the "jps" command but JDK7 does have it.
root#tahirpc:/home/tahir# java -version
java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.3) (**7u71-2.5.3-0ubuntu0.14.04.1**)
OpenJDK 64-Bit Server VM (build 24.65-b04, mixed mode)
root#tahirpc:~# jps
5036 NodeManager
4368 NameNode
4912 ResourceManager
5315 Jps
4773 SecondaryNameNode
4487 DataNode
Use sudo apt-get install openjdk-7-jdk and not openjdk-7-jre. .
For java 8 in ubuntu use the following command.
sudo apt install openjdk-8-jdk-headless
For Hadoop, Oracle JDK 6 preferred, I am not sure if someone has used OpenJDK with Hadoop successfully without any patches. FYI, there had been some talks about support for JDK 7 also. For now, there is too much dependency on Oracle JDK. Hope the dependency goes away soon.
I found it
rpm -qlp java-1.6.0-openjdk-devel-1.6.0.0-1.39.1.9.7.el6.x86_64.rpm | grep jps
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/bin/jps
then
rpm -i java-1.6.0-openjdk-devel-1.6.0.0-1.39.1.9.7.el6.x86_64.rpm
Open syneptics package manager and install openjdk-7-jdk and openjdk-6-jdk package. AFter that jps will work

Where is JAVA_HOME on macOS Mojave (10.14) to Lion (10.7)?

Java is an optional package on the latest versions of macOS.
Yet once installed it appears like the JAVA_HOME environment variable is not set properly.
With the Java optional package or Oracle JDK installed,
adding one of the following lines to your ~/.bash_profile file will set the environment variable accordingly.
export JAVA_HOME="$(/usr/libexec/java_home -v 1.6)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.7)"
or
export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)"
or simply
export JAVA_HOME="$(/usr/libexec/java_home)"
Note: If you installed openjdk on mac using brew, run sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk for the above to work
Update: added -v flag based on Jilles van Gurp response.
/usr/libexec/java_home is not a directory but an executable. It outputs the currently configured JAVA_HOME and doesn't actually change it. That's what the Java Preferences app is for, which in my case seems broken and doesn't actually change the JVM correctly. It does list the 1.7 JVM but I can toggle/untoggle & drag and drop all I want there without actually changing the output of /usr/libexec/java_home.
Even after installing 1.7.0 u6 from Oracle on Lion and setting it as the default in the preferences, it still returned the apple 1.6 java home. The only fix that actually works for me is setting JAVA_HOME manually:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_06.jdk/Contents/Home/
At least this way when run from the command line it will use 1.7. /usr/libexec/java_home still insists on 1.6.
Update: Understanding Java From Command Line on OSX has a better explanation on how this works.
export JAVA_HOME=`/usr/libexec/java_home -v 1.7`
is the way to do it. Note, updating this to 1.8 works just fine.
For me, Mountain Lion 10.8.2, the solution most voted does not work.
I installed jdk 1.7 via Oracle and maven from homebrew.
My solution is from the hadoop-env.sh file of hadoop which I installed from homebrew, too.
I add the below sentence in ~/.bash_profile, and it works.
export JAVA_HOME="$(/usr/libexec/java_home)"
This solution also works for OS X Yosemite with Java 1.8 installed from Oracle.
None of the above answers helped me. I suppose all the answers are for older OS X
For OS X Yosemite 10.10, follow these steps
Use your favorite text editor to open: ~/.bash_profile
//This command will open the file using vim
$ vim ~/.bash_profile
Add the following line in the file and save it ( : followed by "x" for vim):
export JAVA_HOME=$(/usr/libexec/java_home)
Then in the terminal type the following two commands to see output:
$ source ~/.bash_profile
$ echo $JAVA_HOME
In the second line, you are updating the contents of .bash_profile file.
Update for Java 9 and some neat aliases.
In .bash_profile:
export JAVA_HOME8=`/usr/libexec/java_home --version 1.8`
export JAVA_HOME9=`/usr/libexec/java_home --version 9`
Note, that for the latest version it is 9 and not 1.9.
Set active Java:
export JAVA_HOME=$JAVA_HOME8
export PATH=$JAVA_HOME/bin:$PATH
Some additional alias to switch between the different versions:
alias j8='export JAVA_HOME=$JAVA_HOME8; export PATH=$JAVA_HOME/bin:$PATH'
alias j9='export JAVA_HOME=$JAVA_HOME9; export PATH=$JAVA_HOME/bin:$PATH'
Test in terminal:
% j8
% java -version
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
% j9
% java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
EDIT: Update for Java 10
export JAVA_HOME10=`/usr/libexec/java_home --version 10`
alias j10='export JAVA_HOME=$JAVA_HOME10; export PATH=$JAVA_HOME/bin:$PATH'
EDIT: Update for Java 11
export JAVA_HOME11=`/usr/libexec/java_home --version 11`
alias j11='export JAVA_HOME=$JAVA_HOME11; export PATH=$JAVA_HOME/bin:$PATH'
The above didn't work for me with Amazon's EC2 tools, because it expects bin/java etc. underneath JAVA_HOME. /System/Library/Frameworks/JavaVM.framework/Home did work.
For OS X you can do:
export JAVA_HOME=`/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home`
On Mac OS X Lion, to set visualgc to run, I used:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
The following worked for me. I'm using ZSH on OSX Yosemite with Java 8 installed.
The following command /usr/libexec/java_home emits the path to JDK home:
/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
In your ~/.zshrc,
export JAVA_HOME = "/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home"
for macOS Mojave 10.14.1 and JAVA 11.0.1
I set the profile as
export JAVA_HOME=$(/usr/libexec/java_home)
key in terminal this to confirm:
$JAVA_HOME/bin/java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)
A better (more upgradable) way is to use the following:
/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home
This should work with AWS also since it has bin underneath Home
Newer Oracle JVMs such as 1.7.0_21-b12 seem to install here:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
My approach is:
.bashrc
export JAVA6_HOME=`/usr/libexec/java_home -v 1.6`
export JAVA7_HOME=`/usr/libexec/java_home -v 1.7`
export JAVA_HOME=$JAVA6_HOME
# -- optional
# export PATH=$JAVA_HOME/bin:$PATH
This makes it very easy to switch between J6 and J7
I Had to explicitly set it to the exact path on my Macbook air .
Steps followed:
try to echo $JAVA_HOME (if it's set it'll show the path), if not, try to search for it using sudo find /usr/ -name *jdk
Edit the Bash p with - sudo nano ~/.bash_profile
Add the exact path to JAVA Home (with the path from step 2 above)
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home
Save and exit
Check JAVA_Home using - echo $JAVA_HOME
I am running MACOS MOJAVE - 10.14.2 (18C54) on a Macbook Air with JAVA 8
OSX Yosemite, ZSH, and Java SE Runtime Environment 8, I had to:
$ sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands /System/Library/Frameworks/JavaVM.framework/Versions/Current/bin
and in ~/.zshrc change JAVA_HOME to
export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/Current"
For Mac OS X 10.9 I installed the latest version of JRE from Oracle and then reset the JAVA_HOME to /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home.
I am sure there is a better way but this got me up and running.
hughsmac:~ hbrien$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
For Java 11 (JDK 11) it can be located with the following command:
/usr/libexec/java_home -v 11
Got the same issue after I upgrade my Mac OS and following worked for me:
cmd>vi ~/.bash_profile
Add/update the line for JAVA_HOME:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_15.jdk/Contents/Home"
cmd>source ~/.bash_profile or open a new terminal
I think the jdk version might differ, so just use the version which you have under /Library/Java/JavaVirtualMachines/
If you are in need to have multiple versions of JDK under Mac OS X (Yosemite), it might be helpful to add some scripting for automated switching between them.
What you do is to edit your ~/.bash_profile and add the following:
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $#`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
setjdk 1.7
What the script does is to first remove other JDK versions in the PATH so that they won’t interfere with our new JDK version. Then it makes some clever use of /usr/libexec/java_home which is a command that lists installed JDK versions. The -v argument tells java_home to return the path of the JDK with the supplied version, for example 1.7. We also update the PATH to point to the bin directory of the newly found JAVA_HOME directory. At the end we can simply execute the function using
setjdk 1.7
which selects the latest installed JDK version of the 1.7 branch. To select a specific version you can simply execute
setjdk 1.7.0_51
instead. Run /usr/libexec/java_home -V to get more details on how to choose versions.
P.S. Do not forget to source ~/.bash_profile after you save it.
For Fish terminal users on Mac (I believe it's available on Linux as well), this should work:
set -Ux JAVA_8 (/usr/libexec/java_home --version 1.8)
set -Ux JAVA_12 (/usr/libexec/java_home --version 12)
set -Ux JAVA_HOME $JAVA_8 //or whichever version you want as default
This answer is related to Mountain Lion and not Lion. I needed to do this for the AWS Command Line Tools. According to the AWS docs, running which java returns /usr/bin/java.
So, I set JAVA_HOME=/usr in my .bashrc.
Apparently, /usr/bin/java is a symbolic link to /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java which makes it all work.
Update
As mentioned in the comment below, this JAVA_HOME value is not an ideal solution when the JAVA_HOME environment variable is to be used by things other than the AWS Command Line Tools. It works fine for the AWS Command Line Tools, though, as given in their docs.
for mac user .
java 8 should add
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
# JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_05.jdk/Contents/Home
java 6 :
export JAVA_HOME=`/usr/libexec/java_home -v 1.6`
# JAVA_HOME=/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
ref :http://qiita.com/seri_k/items/e978c1339ce51f13e297
For Mac Yosemite,
JDK 1.7.0_xx is using
$ ls -ltar /usr/bin/java
/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_xx.jdk/Contents/Home
Anyone using AUSKEY from the Australian Tax Office (ATO) should uninstall AUSKEY.
This sorted out my JAVA_HOME issues.
It is also no longer required for MAC users. Yah!
I'm using Fish shell on High Sierra 10.13.4 and installed Java via Brew.
It's not automatically set up so to set it correctly on my system I run:
set -U JAVA_HOME (/usr/libexec/java_home)
Just set java_home of 1.8 jdk version in netbeans.conf file:
/Applications/NetBeans/NetBeans 8.2.app/Contents/Resources/NetBeans/etc/netbeans.conf
uncomment line:
netbeans_jdkhome="path/to/jdk"
and set path to your 1.8 jdk, in my case:
netbeans_jdkhome="/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home"
This approach lays you to have several jdk versions on mac os
Handy command for knowing java home and other details.
java -XshowSettings:properties -version
and to know all java homes on your mac:
/usr/libexec/java_home -V

Categories

Resources