views:

360

answers:

3

Hi, I have a web-app, built and compiled in Eclipse, which I want to deploy to my Tomcat 6 (I want to do it manually) and I get a UnsupportedClassVersionError exception which means the JVM tomcat is running is older than the one my eclipse is running. After some checking I see that in the tomcat manager window it says: JVM Version-1.5.0_20-b02 and in my eclipse: Java-Installed JREs- default is pointing at the JDK which is defined as my JAVA_HOME env-var and the one used in my path as the env-var (It's 1.6.013).

My question is how can I tell tomcat to use my JDK? I though that it was supposed to use the JAVA_HOME var but it is defined properly and if I issue java-version in the command prompt I get the proper advanced version.

After doing a bit more checking I saw that under the tomcat library there is a JRE folder which I presume the tomcat is using but if I delete this folder the Tomcat won't start (even after I defined a JRE_HOME env-var and pointed it to the JRE listed under my JDK). So I'm at a loss.

Thanks for any help landed Ittai

Update: As someone asked me I'm using the xampp add-on tomcat.

+1  A: 

There's no JRE in the standard Tomcat 6.0.20 download from Apache. Are you possibly using a pre-packaged/support version like Spring ship?

Either that or someone has modified the standard Tomcat startup to prefer the shipped JRE. How do you start Tomcat? Trace through the startup scripts and see. Or just re-download Tomcat 6 and start again, knowing that you have the canonical installation.

hbunny
I'm using the xampp tomcat add-on version
Ittai
Have you looked through the start up scripts? THere's a setenv.bat file that sets the JRE environment variable. Either change the script, replace the supplied JRE with the version you want or downgrade to Java 1.5.
hbunny
I've looked through some of the scripts but not the one you're referring to, I'll look through it when I'll get home. The idea of replacing the JRE might be what I'll do if I don't find a more straight way of doing it. thanks
Ittai
Thanks very much, in the setenv.bat it was setting the JRE_HOME=%CATALINA_HOME%\jre. So I changed it to JRE_HOME=%JAVA_HOME%\jre. BTW, when I leave it blank the server says that nor JAVA_HOME nor JRE_HOME are defined although echo in cmd outputs that they are defined. thanks.
Ittai
That's because the setenv.bat file resets the usual Java environment variables to ensure that the environment is configured the way it expects.
hbunny
A: 

I would say it's more likely that the app server's JDK would be fixed and the IDE should switch its JDK to match the app server. Don't adjust Tomcat; make Eclipse point to the same JDK that the app server uses.

You don't always have control of the app server, but you can always adjust your IDE.

duffymo
In my case I allways have control of the app server as it is part of the package I'm delivering, but thanks. (besides, I need that JDK version for other development reasons)
Ittai
My points are still pertinent. Your case isn't the rule. And it should be easy enough to switch between JDKs for each project. If Eclipse can't do it, maybe you should switch to a better IDE - IntelliJ.
duffymo
Eclipse can do it.
Thorbjørn Ravn Andersen
A: 

You can either change your Eclipse - > Java -> Compiler setting to compile for Java 1.5 or earlier, or you can install another JRE on your system corresponding to the version being used by Tomcat, and tell Eclipse to use THAT for this project. Eclipse -> Java -> Installed Java runtimes.

Thorbjørn Ravn Andersen