View Full Version : Setting JAVA_HOME after using java-package
offby1
December 25th, 2004, 10:42 PM
Now that I've installed the JDK 1.5 under Warty using java-package to do so, how can I figure out what to set JAVA_HOME to? There doesn't appear to be a simple and single location for this sort of thing.
haha
December 27th, 2004, 11:37 AM
Now that I've installed the JDK 1.5 under Warty using java-package to do so, how can I figure out what to set JAVA_HOME to? There doesn't appear to be a simple and single location for this sort of thing.
run xterm And
$ echo $JAVA_HOME
after this, you can see your java home path
offby1
December 27th, 2004, 11:50 AM
Ah...
If $JAVA_HOME was already set, I would not be asking.
MaV
December 27th, 2004, 07:56 PM
The following method may be a bit complicated ... at least I believe there must be a better solution, but this is what I came up within a few moments' thoughts.
You can get a first hint by typing:
whereis javac
The directory(-ies) shown are not likely the original, and the javac only a symbolic link, so type:
ls -al directory/javac
where directory is the one he printed the first time. This will show you the program it links to.
Continue this until you see something like /usr/lib/j2sdk1.5-sun/bin/javac (that's the result in my case), which is the javac in the original directory. You can prove it by listing the directory; it should contain all the binaries of the SDK. So in my case JAVA_HOME has to be set to /usr/lib/j2sdk1.5-sun.
Greets,
MaV
PS: I won't be online for the next week, so I can't give further help until then, but I'll be glad to hear if you succeded!
kl3rk
December 6th, 2005, 11:37 AM
I think what offby is looking for is this:
user@user:~$ sudo update-alternatives --config java
that should do it!
sphinx
December 6th, 2005, 10:42 PM
I too have had a similar problem. You see, the 'update-alternatives' script is fine if you'd all you want to do is use java from the command line, but as far as I could tell, it didn't set the JAVA_HOME variable.
So why do I want JAVA_HOME set when the commandline worked anyway? well, the startup script for Tomcat needs to have JAVA_HOME set so it can start. So I tried setting JAVA_HOME in /etc/profile. Bingo! that works..... only when starting tomcat manually after you have logged in. Its not set when the initt.d script tries to start it at startup. I suspect /etc/profile is not run by that point.
Currently I have worked around the problem by explicly setting JAVA_HOME in my custom init script for tomcat, but I'd prefer a global place to put environment variables. /etc/profile dosn't seem to be the place.
Slackware has a way of splitting the /etc/profile file up (profile looks for scripts in a set directory, depending on the shell used), so that you can create a file for each group of env variables you want to set up. But my memory of how that all worked is fading as its been a while since I've used slackware.
So is there a global place one can put environment variables so they are available for startup scripts too?
RavenSensei
January 25th, 2006, 02:40 PM
So is there a global place one can put environment variables so they are available for startup scripts too?
I'm looking for the same answer. I installed 1.5 recently and I want to use eclipse as an IDE, but it won't install unless I have JAVA_HOME set and in my path.
A friend of mine told me about editing profile file and putting it there, but that didn't seem to work.
Any ideas? I think if I could set it so that terminal read a file and set it before it started, that might work.
M@
Viro
January 25th, 2006, 03:17 PM
A big hack is to add the definition for JAVA_HOME in .gnomerc, so that it gets set everytime you log into gnome.
Lov
February 12th, 2006, 05:46 AM
user environment vars settings comes from a different file which is /etc/bash.bashrc. You will have to put these lines at the bottom of bash.bashrc:
JAVA_HOME="PATH_TO _YOUR_JAVA_INSTALLATION"
export JAVA_HOME
now all you need to do is logout and login again.
ZylGadis
February 12th, 2006, 12:44 PM
I have set it in my custom init.d script for tomcat, and it works.
pf_
May 22nd, 2006, 12:24 PM
Hi,
I have put the very ugly piece of code in my Makefile to avoid depending on the assumption that JAVA_HOME is set:
ifndef JAVA_HOME
TEST := $(shell which java)
ifdef TEST
JAVA_HOME := $(shell readlink -f $(TEST) | xargs dirname | xargs dirname )
endif
endif
ifdef JAVA_HOME
CXXFLAGS += -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/$(ARCH)
endif
pvasener
June 13th, 2007, 10:49 AM
It seems to me that the cleanest way to proceed is to add the JAVA_HOME variable definition to the /etc/environment file, don't you think?
nicktmro
July 12th, 2007, 06:27 AM
It seems to me that the cleanest way to proceed is to add the JAVA_HOME variable definition to the /etc/environment file, don't you think?
Could not agree more :)
Have a look @ http://tmro.blogspot.com/2007/07/ubuntu-and-java-javahome-no-longer.html if you have issues with launchers as well. Setting the JAVA_HOME in the .bashrc might seem like a good idea if you only need JAVA_HOME in a terminal. But .bashrc won't help if you need to create a launcher for example :)
HTH
paul.reloaded
November 3rd, 2007, 07:00 AM
Hi. I found good solution here: http://www.laliluna.de/blog/2007/02/22/ubuntu_environment_variable_java_home.html
In /usr/lib/jvm are JAVA_HOMEs.
octoberdan
April 27th, 2008, 09:22 PM
Here's a one liner to set it up. This will append JAVA_HOME=... to the last line of /etc/environment. Remember to check in /usr/lib/jvm/ ("ls /usr/lib/jvm") to make sure you're setting it to something that exists:
sudo bash -c "echo JAVA_HOME=/usr/lib/jvm/java-6-sun/ >> /etc/environment"
I bother responding again because this is the second response for googling "ubuntu java_home" which is common enough to be included in the autocomplete search bar of firefox.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.