• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to Setup the JDK Correctly

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author & internet detective
Posts: 42145
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?


 
Saloon Keeper
Posts: 28696
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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.
 
malcon lopez
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 28696
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 28696
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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.
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

 
Tim Holloway
Saloon Keeper
Posts: 28696
211
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To my knowledge, update-alternatives updates JDK as well.

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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic