Enviroment Variable for Java

Issues related to applications and software problems
Post Reply
brokenbones
Posts: 3
Joined: 2017/12/15 11:37:39

Enviroment Variable for Java

Post by brokenbones » 2017/12/15 11:50:34

Hi there guys!

First post here. I'm really new with Red Hat based Linux system, so maybe that's the reason of not reaching my goal. Here is the scenario:

So I'm trying to set up a soft wich starts (and needs) with a script wich uses java. The start.sh script is something like this:

Code: Select all

java name-of-the.jar -parameter1 -parameter2
The problems is that i don't have java runtime enviroment's binary based on /usr/bin, what i mean is when i try to launch java just using command "java" on the terminal it does not recognize it, obviously, cause it's located in another path

I can launch the the scripts using:

Code: Select all

/path/to/the/binary/./java name-of-the.jar -parameter1 -parameter2
And is all cool, but after the app itself uses java again, and not finding it, it stops. I have done a lot of system file manipulation like in bashcr /etc/profile and stuff like that, but i think, the most representative proof is what's happens when i try to set the enviroment variable just by terminal

So I tried:

Code: Select all

set JAVA_PATH=/path/to/the/binary/ (with and without the "/" at the very end)
export JAVA_PATH
And then i verified if it's correct using

Code: Select all

printenv JAVA_PATH
Answer

Code: Select all

/path/to/the/binary/:
It looks like correct to me, but anyway, i'm missing something there... could you help me please?

Thanks a lot guys, see ya later!

User avatar
TrevorH
Site Admin
Posts: 33202
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Enviroment Variable for Java

Post by TrevorH » 2017/12/15 12:03:01

Use the alternatives command to set the default java to run. Something like alternatives --install /usr/bin/java java /usr/java/latest/bin/java 1 then use alternatives --config to make that the default.
The future appears to be RHEL or Debian. I think I'm going Debian.
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 and 6 are deadest, do not use them.
Use the FAQ Luke

brokenbones
Posts: 3
Joined: 2017/12/15 11:37:39

Re: Enviroment Variable for Java

Post by brokenbones » 2017/12/15 12:07:19

Thanks for the Reply!! (pretty fast!!)

Will try that, but the soft I'm trying to launch is made in my company, and (not sure) it needs specifically the 7th version of Java.
Anyway, I'll try that, but before doing it, and just in case, how can i revert the process?? I don't want to mess it up since it's my first week here LOL

Once again, thanks for ur support

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: Enviroment Variable for Java

Post by hunter86_bg » 2017/12/15 18:50:36

With alternatives you can have multiple versions of Java (and other software) and switch between the needed versions with the simple 'alternatives --config'.

brokenbones
Posts: 3
Joined: 2017/12/15 11:37:39

Re: Enviroment Variable for Java

Post by brokenbones » 2017/12/18 08:04:51

Hi there guys!

First of all, thanks for ur support

Just let u know that i figured out what was going on. The thing is that i forgot just one comand. Using as 3º and last command:

Code: Select all

export PATH=$JAVA_HOME/bin:$PATH
i can call java now in the terminal just putting "java" in the command line

Anyway, the solution u bring here it's really interesting and i'm pretty sure that will be useful in the future

Thanks!

Post Reply