*
The moose likes Tomcat and the fly likes How to Setup the JDK Correctly Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "How to Setup the JDK Correctly" Watch "How to Setup the JDK Correctly" New topic
Forums: Tomcat Linux / UNIX
Author

How to Setup the JDK Correctly

malcon lopez
Greenhorn

Joined: Feb 18, 2014
Posts: 7
Hello,

Initially I installed the openjdk , but I found that My Web App does not run so that this openjdk version and some mistakes in the configuration, right now I have installed the jdk1.7.0_51 on my.
I also typed this on the ssh.

export PATH=/usr/lib/jvm/jdk1.7.0_51/bin:/usr/lib/jvm/jdk1.7.0_51/db/bin:$PATH
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_51
export DERBY_HOME=/usr/lib/jvm/jdk1.7.0_51/db/bin

Everything's ok, however when I exit from the console and type the java -version still shows me

java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1~deb7u1)
OpenJDK Client VM (build 20.0-b12, mixed mode, sharing)

Not the latest one.

Could anyone help me to solve this problem. I will be happy
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30299
    
150

If you type this command, does it show your changes to the path? (I'm guessing it doesn't.)
echo $PATH

When you say you exit from the console, does that mean opening a new SSH connection or something else?



[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

"export" doesn't promote the environment assignment to other command shells. It merely ensures that the assignment will be visible in the child shells your current shell spawns.

As long as you have JAVA_HOME set to the proper JDK in the shell that launches Tomcat, its value in other shells doesn't matter.

Although I don't have much use for IcedTea myself, so I do my exports for things like JAVA_HOME at a higher level. There are many places to do this. One is the profile of the user account that Tomcat is launched under. Another is the set of profiles used globally by the various shells and defined in the /etc directory.


Customer surveys are for companies who didn't pay proper attention to begin with.
malcon lopez
Greenhorn

Joined: Feb 18, 2014
Posts: 7
Jeanne Boyarsky wrote:If you type this command, does it show your changes to the path? (I'm guessing it doesn't.)
echo $PATH

When you say you exit from the console, does that mean opening a new SSH connection or something else?



Hi Jeanne ,

Thanks for your reply, I type this echo $PATH and prints "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.6.0-openjdk-i386/bin
" it is still using the openjdk version not the Oracle JDK that it is located at /usr/share/java/jdk1.7.0_51

When you say you exit from the console, does that mean opening a new SSH connection or something else?
Just opening another SSH with the same IP of the server, it seems that does not save the path configuration and does not work my app web.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

If you're using the catalina.sh control script that came with Tomcat, it executes Java as "$JAVA_HOME/bin/java". Your PATH settings should immaterial, since the path of the appropriate java runtime is fully qualified in the control script.
malcon lopez
Greenhorn

Joined: Feb 18, 2014
Posts: 7
Tim Holloway wrote:"export" doesn't promote the environment assignment to other command shells. It merely ensures that the assignment will be visible in the child shells your current shell spawns.

As long as you have JAVA_HOME set to the proper JDK in the shell that launches Tomcat, its value in other shells doesn't matter.

Although I don't have much use for IcedTea myself, so I do my exports for things like JAVA_HOME at a higher level. There are many places to do this. One is the profile of the user account that Tomcat is launched under. Another is the set of profiles used globally by the various shells and defined in the /etc directory.


I followed many tutorials and I don't know how to config it!
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19



There's also startup.sh and shutdown.sh (.bat) files in CATALINA_HOME/bin. I just happen to prefer invoking the master control script directly.

The JRE_HOME, CATALINA_BASE and other Tomcat environment variables will get their values as defaults based on JAVA_HOME and CATALINA_HOME, so those are the only 2 that count.

As I said before. Tomcat doesn't actually care what the PATH is set to, since it uses explicity command paths. I'm not sure about your DERBY_HOME setting. It's not a bad idea to create a $CATALINA_HOME/bin/setenv.sh file and put the export for DERBY_HOME there, though. You can also override Tomcat's JAVA_OPTS in setenv.sh if you want to override the default VM memory sizes and stuff.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1505
    
    5

Hi malcon,

If I understand your requirement - you want to change default Java version on your system. If this is correct, and you've installed various Java versions (i.e. not copy-pasted installation directories), then below command might be helpful:



Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16012
    
  19

I really hate the "alternatives" system. It's confusing and awkward.

What it's supposed to do, however, is allow substitution of competing implementations of various complex programs by effectively re-wiring the system resource locations on a per-user basis.

You don't need that to run Tomcat, since the third-party Java developer kits such as the one from Sun/Oracle are designed to be hosted in a single unzipped directory and Tomcat in particular can work just fine as long as you set JAVA_HOME to point to that directory.

Actually, I'm not sure "alternatives" handles the JDK. It may only support JREs. I'm not certain, since, as previously mentioned, I don't use it.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1505
    
    5

To my knowledge, update-alternatives updates JDK as well.

I tried to change the version and new version is reflected in both below commands:

 
Don't get me started about those stupid light bulbs.
 
subject: How to Setup the JDK Correctly