I have tried setting my JAVA_HOME variable for Hadoop to no avail.
My Java runtime is in /usr/bin/java, but Hadoop keeps trying to access it in /usr/bin/java/bin/java.
I have set the JAVA_HOME in my .bash_profile and in bin/hadoop, but neither works. I am guessing that some other path setter is overriding this. Is this a known problem and what can be done about it?
A couple of other things I tried:
echo $JAVA_HOME from the hadoop script
add $JAVA_HOME to the conf/hadoop-env.sh
In your case:
JAVA_HOME = /usr
The code assumes that the executable is located at:
$JAVA_HOME/bin/java
It's unlikely your Java installation is in /usr/bin/java.
The executable may be there, or may just be a link to the executable in your installation.
IMO it's cleaner to use your actual Java JDK/JRE directory and use that instead: that's what JAVA_HOME is supposed to be.
Using Hadoop is quite a bit more complicated than setting an environment variable correctly; you may be in for a rough road. Consider something like Kiji's Bento Box to ease initial setup.
Related
I'm fairly new to Java. Many of the tutorials on installing Java on a Mac recommend setting up the JAVA_HOME environment variable. However, Java works fine on my computer with the JAVA_HOME variable being empty!
I have successfully used Java from the command line (using javac and java), in IntelliJ IDEA (there in the "Project Structure Settings" I've set up the "JDK home path" to /Library/Java/JavaVirtualMachines/jdk-16.0.1.jdk/Contents/Home) and in Sublime Text to compile and run Java files.
So, my questions are:
Why does Java work without the JAVA_HOME on my Mac?
Do I need to set up JAVA_HOME at all? What would be the consequences of not having it? Maybe it is not essential for some things, but is required for other things to work? Then what are these things?
Is this behavior different on other operating systems?
Outputs of some commands are:
echo $JAVA_HOME outputs an empty line
echo $CPPFLAGS outputs an empty line
which java
/usr/bin/java
echo $PATH contains /usr/bin
Why does Java work without the JAVA_HOME on my Mac?
Setting JAVA_HOME is not required for Java to work in your system. Some applications (e.g. Tomcat, Maven etc.) however look for JAVA_HOME system variable and if its value is not set, they may prompt you to do so.
Do I need to set up JAVA_HOME at all? What would be the consequences
of not having it? Maybe it is not essential for some things, but is
required for other things to work? Then what are these things?
Already answered above.
Is this behavior different on other operating systems?
It's same across all operating systems.
It depends on the program.
Most programs that depend on Java follow logic like this
if $JAVA_HOME ; then
use JAVA_HOME/bin/java
elif $(which java); then
use java command on PATH
else
error
fi
That being said, to be consistent, you should set it , and using SDKman or Homebrew does that for you
I am trying to build some binaries of an application. When i am trying to make the build, I am getting this:
BUILD FAILED
/home/.../ant-build.xml:84: Unable to find a javac compiler;
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK.
It is currently set to "/usr/lib/jvm/java-8-openjdk-amd64/jre"
The application requires java 7, and i have it installed but i had it along java 8. The build requires for tools.jar which is located in java 7 only, therefore after several attempts i uninstalled java 8. However, when I am trying make again, i get the same error, even though i don't have java8 installed at all!
I set the JAVA_HOME properly:
$ echo $JAVA_HOME
/usr/lib/jvm/java-7-openjdk-amd64/
I doubt i need the path but i set that one up just in case as well :
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/java-7-openjdk-amd64/bin
I'm running out of ideas here :P any help would be appreciated.
Also something maybe important, I had to add the repo manually to get java-7 otherwise it wasnt able to locate the package. Thats when i got double jdk-s.
I guess you are calling the JAVAC command from any other source/tool like Jenkins/Bamboo/Teamcity. Make sure you have set the environment variable of that tool. usually it lies in the manage tool option.
I was facing same issue while using Jenkins.If you don't set up an environment variable in tool from which you are making a call it take your
"/usr/lib/jvm/java-8-openjdk-amd64/jre" so go and set the the env variable JAVA_HOME of you tools. attaching screen shot of Jenkins issue. Go to Manage Jenkins -->configure system --> environment variables and set you java_home path.
Cheers
I just encountered the same situation.
That is because JAVA_HOME is not correctly set in sudo environment.
I added export JAVA_HOME=/path/to in /root/.bashrc, and eventually it was built right.
It seems that you are using javac of java8 with JAVA_HOME or CLASS_PATH pointing to java7.
You can use which java to check that.
export JAVA_HOME=/lib/jvm/java-7-openjdk-amd64
export export ${PATH}=${JAVA_HOME}:/bin:${PATH}`
I have Ubuntu 10.10 with java already installed. I am able to execute java command from any folder. I supposed that could be because I had java Classpath setted. But neither JAVA_HOME nor CLASSPATH are setted.
If I look at /etc/environment content I can see that PATH is setted to /usr/bin/ (among others). As 'which java' returns /usr/bin/java, is that the reason why I can execute java from anywhere? If not, why is it?
You can execute java because the command is on your path.
echo $PATH
will show you which directories are searched, in which order to find a particular program. Since /usr/bin is on your path, when you type java it will eventually look at /usr/bin/java. Note that in many systems this is a symbolic link (a file that points to another file) so /usr/bin/java often points to /etc/alternatives/java (which is also a symbolic link that points to the real executable).
Where the environmental variable JAVA_HOME comes into play is in tools and programs that check for JAVA_HOME and act on it instead of relying on the path. In most modern Linux systems, the work done by the alternatives subsystem replaces the earlier (more problematic) JAVA_HOME technique. That said, you might want to set JAVA_HOME anyway, should you encounter a tool that demands it.
One reason why JAVA_HOME is not as popular as it could be is that to access JAVA_HOME you need to run a shell, and not everyone wants to wrap every single Java item in a shell command.
Yes, if java binary (or a link to it) is on a folder that is listed on the path then you can execute java without specifying the path to it (for example /usr/local/java/latest/bin/java -jar x.jar)
JAVA_HOME and CLASSPATH have nothing to do with system path.
JAVA_HOME allow other software (or scripts) to know where to look for java installation.
CLASSPATH tells java where to look for classes (.class files resulting of compiling .java files).
OK, what am I doing wrong, this is driving me nuts.
I am trying to install the latest JDK (1.6.0_23). So, I downloaded it from Oracle's awful site and then ran the installation. I installed it to C:\Java\jdk1.6.0_23
Then, I created a JAVA_HOME User Variable that pointed to C:\Java\jdk1.6.0_23. I then added a piece to the end of my Path environment variable that says %JAVA_HOME%\bin.
However, when I try to simply open a command prompt and run simple java commands, I am told it is not a recognizable command. I have to manually cd into the that bin directory to do anything.
Do I also need a Classpath variable that points to the JRE? I noticed there was a Classpath variable there previously that pointed to jre/lib/QTJava.zip, but I deleted it.
If you have the JDK installed and a JAVA_HOME variable setup, do I still need the JRE in the classpath? I am running Windows 7 and do all of my development in Eclipse.
Maybe the problem is because you set JAVA_HOME as a user variable, but trying to reference it from the PATH which is a system variable (or is it?). You cannot do this, because system variables are evaluated before user variables.
There are two possible solutions:
1. Set JAVA_HOME as a system variable instead
2. Create a new user variable PATH and set %JAVA_HOME%\bin there. The user PATH and the system PATH variables will be concatenated at runtime automatically.
From http://social.answers.microsoft.com/Forums/en-US/vistainstall/thread/48b23109-9fbc-47c5-a5d1-465773f94704
(at the end)
1) Enable 'delayed variable expansion'
in the registry (see
http://batcheero.blogspot.com/2007/06/how-to-enabledelayedexpansion.html)
2) Change the '%' signs around var2 to
'!', e.g. "%var2%" becomes "!var2!"
I've done some limited testing on
Windows 7 and this appears to fix the
problem.
Maybe try that, see if it fixes it (I don't have windows here to try)
Do I also need a CLASSPATH variable that points to the JRE?
Strictly speaking, no. The CLASSPATH variable may be used if you try to run a java class and you don't use the -cp or -jar options.
The CLASSPATH variable doesn't need to point to the JRE. The java.exe command etc all know where to find the JRE's runtime classes. (And they don't look on the CLASSPATH for them anyway.)
For the PATH problem, try running:
C:\Java\jdk1.6.0_23\bin\java.exe -version
If that doesn't work then there's a problem with your actual installation. If it does work, try looking at what JAVA_HOME and PATH are set to in the environment variables of the command shell.
I do most of my work against JDK 1.5 - but occasionally I have to change to 1.6. it is a bit painful to have to manually go and change my 'JAVA_HOME' system variable whenever I need to work on a project specific to one or the other (and no, Eclipse doesn't play well in these scenarios - trust me...I've tried.)
I'm looking for a registry script or windows shell script or for that matter any means by which I can "toggle" this system variable with something that is easy to run.
I've messed with the 'set' command, but that only sets the variable for that particular command instance - not globally.
Thanks in advance.
EDIT #1:
Points of advise:
Use the JAVA_HOME variable in your path variable as well, that way you only have to change the JAVA_HOME (which is used in many projects anyways [maven, ant, etc])
Write the command into a couple batch scripts for easy use
When you make the change the windows command session will not reflect it right away. You must close and reopen it.
You could use setx for that purpose
Like so:
setx /M JAVA_HOME "C:\Program Files (x86)\Java\jdk1.6.0_17"