PDA

View Full Version : Setting JAVA_HOME after using java-package



offby1
December 26th, 2004, 04:42 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.

haha
December 27th, 2004, 05:37 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.

run xterm And

$ echo $JAVA_HOME

after this, you can see your java home path

offby1
December 27th, 2004, 05:50 PM
Ah...

If $JAVA_HOME was already set, I would not be asking.

MaV
December 28th, 2004, 01:56 AM
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, 05:37 PM
I think what offby is looking for is this:

user@user:~$ sudo update-alternatives --config java

that should do it!

sphinx
December 7th, 2005, 04:42 AM
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, 08: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, 09: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, 11: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, 06:44 PM
I have set it in my custom init.d script for tomcat, and it works.

pf_
May 22nd, 2006, 05: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, 03:49 PM
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, 11: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, 01:00 PM
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 28th, 2008, 02:22 AM
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.

vintermann
January 16th, 2009, 01:28 PM
Thanks Octoberdan, I was looking for the "clean" way of getting JAVA_HOME set.

Ideally, though, I'd like JAVA_HOME to be set to the same jre I chose with update-java-alternatives, since I need to switch back and forth now and then. I don't understand why update-java-alternatives doesn't just do it, but...

I thought I would be clever and run "which" with some dereferencing option to see where that symlink points to, but that doesn't seem to exist. I can't find any tool to dig through multiple file symlinks, in fact.

gaoagong
June 15th, 2009, 09:31 AM
Sphinx,

How come /etc/profile is not the right place to put it? I am trying to run Intellij IDEA and it asks me to set up JAVA_HOME. At first I just put it in my local user bash.rc file, but it is really annoying to start the program manually from command line. Eventually, I came to the conclusion that I had to put it either in /etc/bash.rc or /etc/profile. I now just click on an icon to run Intellij.

Are there side effects to putting it in there?

It seems to me that /etc/invironment is where I should put it? I guess I'll just do that.

homepig
March 24th, 2010, 08:23 AM
after you get to know where your java is installed, do:

1. only can run cmd line jedit
sudo vim /etc/bash.bashrc
and add
JAVA_HOME=/usr/lib/jvm/java-6-sun
export JAVA_HOME

2. support gui jedit
sudo vim /etc/environment
and add
JAVA_HOME="/usr/lib/jvm/java-6-sun"

SETodd
June 4th, 2010, 10:21 PM
/etc/environment is exactly what I was looking for but didn't know existed. Thanks!

albertwt
November 12th, 2010, 09:37 AM
after you get to know where your java is installed, do:

1. only can run cmd line jedit
sudo vim /etc/bash.bashrc
and add
JAVA_HOME=/usr/lib/jvm/java-6-sun
export JAVA_HOME

2. support gui jedit
sudo vim /etc/environment
and add
JAVA_HOME="/usr/lib/jvm/java-6-sun"


tahnks man after you showed to me how to add the java_home, however it didn't show up when i type the echo?


root@SSV:~# vi /etc/environment
root@SSV:~# echo $JAVA_HOME

root@SSV:~# export JAVA_HOME
root@SSV:~# echo $JAVA_HOME

root@SSV:~#


any idea in how to do this ?

a_nini75
May 29th, 2011, 06:50 AM
[/CODE]any idea in how to do this ?

Hello, me too found out how, in another ubuntuforums thread:

http://ubuntuforums.org/showthread.php?t=376632

so it seems that it's as simple as issue this command from a terminal:

source /etc/environment