I have the following on my .bashrc:
JAVA_HOME="/usr/bin/java"
GRAILS_HOME="/root/grails"
PATH=$PATH:$JAVA_HOME:$GRAILS_HOME/bin
export JAVA_HOME
export GRAILS_HOME
export PATH
However, when I execute > grails in the terminal, I get:
root#localhost:~# grails
grails: JAVA_HOME is not a directory: /usr/bin/java
when I tried to replace to
JAVA_HOME="/usr/share/java"
then the outcome is:
root#localhost:~# grails
grails: JAVA_HOME is not defined correctly; can not execute: /usr/share/java/bin/java
what am I missing in there?
I would expect JAVA_HOME to contain the bin directory containing java (and others).
So clearly those two options you've selected are not correct.
Looking at my Ubuntu installation, I have numerous Java packages under /usr/lib/jvm, and I would select an appropriate one there e.g.
export JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
Make sure to source the changed file eg: $ source [filename of the changes made] in your example .bashrc
Related
I've installed Spark 2.1.1 on Ubuntu and no matter what I do, it doesn't seem to agree with the java path. When I run "spark-submit --version" or "spark-shell" I get the following error:
/usr/local/spark/bin/spark-class: line 71: /usr/lib/jvm/java-8-openjdk-amd64/jre/bin//bin/java: No such file or directory
Now obviously the "/bin//bin/java" is problematic, but I'm not sure where to change the configuration. The spark-class file has the following lines:
if [ -n "${JAVA_HOME}" ]; then
RUNNER="${JAVA_HOME}/bin/java"
I was originally using a version of Spark meant for Hadoop 2.4 and when I changed it to "RUNNER="${JAVA_HOME}" it would either give me the error "[path] is a directory" or "[path] is not a directory." This was after also trying multiple path permutations in /etc/environment
What I now have in /etc/environment is:
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/"
This is the current java setup that I have:
root#ubuntu:~# 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
bashrc has the following:
export SPARK_HOME="/usr/local/spark"
export PATH="$PATH:$SPARK_HOME/bin"
Can anyone advise: 1) What files I need to change and 2) how I need to change them? Thanks in advance.
spark-class file is in the link, just in case:
http://vaughn-s.net/hadoop/spark-class
In the /etc/environment file replace
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/
with
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre/
then execute
source /etc/environment
also RUNNER="${JAVA_HOME}/bin/java" should be kept as it is
Windows Environment:
Open Advanced system settings -> Environment Variables to set JAVA_HOME path, and the most common mistake is setting the path to JAVA folder:
JAVA_HOME: Directory-Name:\java
rather than setting it to JDK folder
JAVA_HOME: Directory-Name:\jdk
This is how it worked for me.
I try to set JAVA_HOME variable on an ubuntu server. I get the Java path with this command
which java
/usr/bin/java
I set the result in /etc/environment
JAVA_HOME="/usr/bin/java"
When I try to run a mvn command I get this error
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/bin/java/bin/java
You should not set JAVA_HOME to /usr/bin/java, because that's just a symbolic link to the java executable, which points to where the real executable is.
JAVA_HOME should point to the Java installation directory, and not to the java executable (or a link to the executable).
Find out where your Java installation directory is and then set JAVA_HOME to that directory (and not to the java executable). If you installed Java using Ubuntu's package management system, then the Java home directory is probably one of the subdirectories in /usr/lib/jvm.
Per the Oracle site:
export JAVA_HOME=jdk-install-location
export PATH=$JAVA_HOME/bin:$PATH
You can add these lines into your ~/.bash_profile (or ~/.bashrc), and then refresh using source ~/.bash_profile
I installed ant in my system, when I run ant command, I get following error:
Error: JAVA_HOME is not defined correctly. We cannot execute
/usr/lib/jvm/java-6-sun/bin/bin/java
Please suggest what should I do?
Set the environment variable JAVA_HOME to the installation directory of your JDK, which is: /usr/lib/jvm/java-6-sun
It looks like you have set it to /usr/lib/jvm/java-6-sun/bin (note the /bin at the end); the ant command appends another /bin so that you get .../bin/bin/java which is incorrect.
In your Java installation directory, u can see a jre subdirectory that contains the bin directory that contains java and related executables.
So you should probably be setting JAVA_HOME to /usr/lib/jvm/jdk/jre rather than /usr/lib/jvm/jdk.
I am new at web-services. I am trying to generate the stubs using this command:
wsimport -d ./build -s ./src -p com.ECS.client.jax http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl -b jaxws-custom.xml
I am getting this error in the cmd:
wsimport is not recognized
My Java environment variable system path is C:\Program Files (x86)\Java\jdk1.7.0. What am I doing wrong?
I resolved this issue by using wsimport from netbeans not from cmd...but I still don't know why I couldn't use it from cmd.
C:\Program Files\Java\jdk1.7.0_60\bin
This is where my jdk is, works for my system:
Go to My computer >> right click and select properties.
On the properties tab select Advanced system settings (Windows 7)
Click enviroment variables
select path and click edit option
add
";C:\Program Files\Java\jdk1.7.0_60\bin"
at the end.
Done.
wsimport and all other java commands are present in jdk bin directory and hence you need to update your PATH variable to include:
"C:\Program Files (x86)\Java\jdk1.7.0\bin"
instead of
"C:\Program Files (x86)\Java\jdk1.7.0"
I offer to create JAVA_HOME path. For example my JAVA_HOME:
JAVA_HOME c:\Java\jdk1.6.0_26\
My java path not include any special character and spacing between characters. Windows Path included this:
%JAVA_HOME%\bin;
or:
c:\Java\jdk1.6.0_26\bin;
Please check your Path. May be included wrong character, another slash, second java path or not included semicolon.
your java path is not set properly. what you can do is.
go to your java bin folder in your cmd prompt like c:\java\jdk.1.7.0\bin and enter your command like wsimport or wsimport -keep -s blahblahblah.
This will work!!!
You can also do this instead of changing the enviroment path variables
'C:\Program Files\Java\jdk1.8.0_60\bin\wsimport.exe'
And simply execute your code like:
'C:\Program Files\Java\jdk1.8.0_60\bin\wsimport.exe' -d ./build -s ./src -p com.ECS.client.jax http://webservices.amazon.com/AWSECommerceService/AWSECommerceService.wsdl -b jaxws-custom.xml
I know this is an old post but I found this solution today and this was the way I solved!
Go to the environment variable. Under system variable choose "PATH" and edit it. In the new dialog box append path till bin folder of jdk. It MUST work.
If you're on linux and can't find wsimport as a default shell command, you might want to install openjdk-devel.
Actually the problem for this issue is system is not finding the java on the path variable. Eventually the command will work after adding the java on your system path variable..
This is the best solution for this problem:
run on your cmd this line:
c:>set path=%path%;C:\Program Files\Java\jdk1.8.0_51\bin
It should work.
I found it on
http://www.skylit.com/javamethods/faqs/javaindos.html
I just delete the entry in path as %JAVA_HOME%\bin and provide the direct path as C:\Program Files\Java\jdk1.8.0_101\bin . I don't know why because previously also it was pointing to same directory only.
Many Java applications that use shell scripts to configure their environment use the JAVA_HOME environment variable to start the correct version of Java, locate JRE JARs, and so on.
In macOS X 10.6, the following paths seem to be valid for this variable
/Library/Java/Home
/System/Library/Frameworks/JavaVM.framework/Home
/System/Library/Frameworks/JavaVM.framework/Versions/Current
Some of these are symlinks to the actual current VM (as defined in the Java Preference pane).
But which one should be used—or is it okay to use any of them?
I just set JAVA_HOME to the output of that command, which should give you the Java path specified in your Java preferences. Here's a snippet from my .bashrc file, which sets this variable:
export JAVA_HOME=$(/usr/libexec/java_home)
I haven't experienced any problems with that technique.
Occasionally I do have to change the value of JAVA_HOME to an earlier version of Java. For example, one program I'm maintaining requires 32-bit Java 5 on OS X, so when using that program, I set JAVA_HOME by running:
export JAVA_HOME=$(/usr/libexec/java_home -v 1.5)
For those of you who don't have java_home in your path add it like this.
sudo ln -s /System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java_home /usr/libexec/java_home
References:
Oracle explains the java_home command
An article for configuring the JDK in Spring Tool Suite (Eclipse
2019) on MacOS
Also, it`s interesting to set your PATH to reflect the JDK. After adding JAVA_HOME (which can be done with the example cited by 'mipadi'):
export JAVA_HOME=$(/usr/libexec/java_home)
Add also in ~/.profile:
export PATH=${JAVA_HOME}/bin:$PATH
P.S.: For OSX, I generally use .profile in the HOME dir instead of .bashrc
I am having MAC OS X(Sierra) 10.12.2.
I set JAVA_HOME to work on React Native(for Android apps) by following the following steps.
Open Terminal (Command+R, type Terminal, Hit ENTER).
Add the following lines to ~/.bash_profile.
export JAVA_HOME=$(/usr/libexec/java_home)
Now run the following command.
source ~/.bash_profile
You can check the exact value of JAVA_HOME by typing the following command.
echo $JAVA_HOME
The value(output) returned will be something like below.
/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
That's it.
I'm on Mac OS 10.6.8
The easiest solution works for me is simply put in
$ export JAVA_HOME=$(/usr/libexec/java_home)
To test whether it works, put in
$ echo $JAVA_HOME
it shows
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
you can also test
$ which java
Nowadays Java seems to be installed in /Library/Java/JavaVirtualMachines
I tend to use /Library/Java/Home. The way the preferences pane works this should be up to date with your preferred version.
That above works not any more in YOSEMITE for GRAPHICAL APPLICATIONS! Like eclipse, or anything started with Spotlight. (.bash_profile, launchd.conf works for terminal sessions only.)
Before starting eclipse, just open a terminal window, and give out the following command:
launchctl setenv JAVA_HOME /Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home
(With your installation path! Perhaps works with $(/usr/libexec/java_home) instead of the full path too.)
View the whole excellent article about the permanent solution here:
Setting environment variables via launchd.conf no longer works in OS X Yosemite/El Capitan/macOS Sierra?
It is recommended to check default terminal shell before set JAVA_HOME environment variable, via following commands:
$ echo $SHELL
/bin/bash
If your default terminal is /bin/bash (Bash), then you should use #hygull method
If your default terminal is /bin/zsh (Z Shell), then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
This method tested working in macOS Mojave Version 10.14.6.
I've found this stack to help, i was having the same issue and i could fix:
My java path was here:
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
and was needed to put into my .bash_profile:
export JAVA_HOME=\"/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home\"
Hope help
As other answers note, the correct way to find the Java home directory is to use /usr/libexec/java_home.
The official documentation for this is in Apple's Technical Q&A QA1170: Important Java Directories on OS X: https://developer.apple.com/library/mac/qa/qa1170/_index.html
For me maven seems to work off the .mavenrc file:
echo "export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)" > ~/.mavenrc
I'm sure I picked it up on SO too, just can't remember where.
Create file ~/.mavenrc
then paste this into the file
export JAVA_HOME=$(/usr/libexec/java_home)
test
mvn -v
Skipping Terminal setup since you mentioned applications, permanent system environment variable set up (works for macOS Sierra; should work for El Capitan too):
launchctl setenv JAVA_HOME $(/usr/libexec/java_home -v 1.8)
(this will set JAVA_HOME to the latest 1.8 JDK, chances are you have gone through serveral updates e.g. javac 1.8.0_101, javac 1.8.0_131)
Of course, change 1.8 to 1.7 or 1.6 (really?) to suit your need and your system
For Fish Shell users, use something like the following: alias java7 "set -gx JAVA_HOME (/usr/libexec/java_home -v1.7)"