ChatGPT解决这个技术问题 Extra ChatGPT

How to change Java version used by TOMCAT?

I have Java 1.6 and Tomcat 5.5 installed on my system.

But Tomcat 5.5 accesses Java 1.5 and hence as the outcome I get the error Bad version number in .class file while executing java code with JSP.

How can I change the Tomcat version to Java 1.6?

UPDATE

I tried changing the JVM that the tomcat5w.exe is pointing to the version 1.6 and now I am out of the Bad version in .class file error. But now, I get the following error.

exception

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:498)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

root cause

java.lang.NullPointerException
myfirst.SearchLink.checkURL(SearchLink.java:20)
org.apache.jsp.Test_jsp._jspService(Test_jsp.java:52)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:369)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:308)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:259)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)

What might be the root cause?

your exception now is completely different. It's for a new question. (but do some search before that ;) )
I rectified the issue... Thanks a lot for your support Bozho.. Sincere Thanks
Check Tomcat Tutorial: tomcat.apache.org/tomcat-8.5-doc/windows-service-howto.html , e.g. tomcat7 //US/Tomcat7 --JavaHome D:\Java8

C
Community

When you open catalina.sh / catalina.bat, you can see :

Environment Variable Prequisites JAVA_HOME Must point at your Java Development Kit installation.

So, set your environment variable JAVA_HOME to point to Java 6. Also make sure JRE_HOME is pointing to the same target, if it is set.

Update: since you are on Windows, see here for how to manage your environment variables


I could not find both these file catalina.sh / catalina.bat in my Tomact 5.5 folder
they are in /bin. But this is not the point. You have to set the environment variables. Don't touch the catalina files.
You mean changing JVM C:\Program Files\Java\jre1.5.0_04\bin\client\jvm.dll from this?
JAVA_HOME is directing to version 1.6 only.. But when i used the code out.println("Java Version = "+ System.getProperty("java.version")); in my jsp code I got the version as 1.5.0_04 \
and what is the output of running startup.bat ? There should be 4 lines showing different _HOME variables.
k
koppor

You can change the JDK or JRE location using the following steps:

open the terminal or cmd. go to the [tomcat-home]\bin directory. ex: c:\tomcat8\bin write the following command: Tomcat8W //ES//Tomcat8 will open dialog, select the java tab(top pane). change the Java virtual Machine value. click OK.

note: in Apache TomEE same steps, but step (3) the command must be: TomEE //ES


For some reason I had the default Java path checked off
N
Nick Grealy

If you use the standard scripts to launch Tomcat (i.e. you haven't installed Tomcat as a windows service), you can use the setenv.bat file, to set your JRE_HOME version.

On Windows, create the file %CATALINA_BASE%\bin\setenv.bat, with content: set "JRE_HOME=%ProgramFiles%\Java\jre1.6.0_20" exit /b 0

And that should be it.

You can test this using %CATALINA_BASE%\bin\configtest.bat (Disclaimer: I've only checked this with a Tomcat7 installation).

Further Reading:

http://tomcat.apache.org/tomcat-5.5-doc/RUNNING.txt - Section: 'Advanced Configuration - Multiple Tomcat Instances'

http://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt - Section: '(3.4) Using the "setenv" script (optional, recommended)'


R
ROMANIA_engineer

In Eclipse it is very easy to point Tomcat to a new JVM (in this example JRE6). My problem was I couldn't find where to do it. Here is the trick:

On the ECLIPSE top menu FILE pull down tab, select NEW, -->Other ...on the New Server: Select A Wizard window, select: Server-> Server... click NEXT . on the New Server: Define a New Server window, select Apache> Tomcat 7 Server ..now click the line in blue and underlined entitled: Configure Runtime Environments on the Server Runtime Environments window, ..select Apache, expand it(click on the arrow to the left), select TOMCAT v7.0, and click EDIT. you will see a window called EDIT SERVER RUNTIME ENVIRONMENT: TOMCAT SERVER On this screen there is a pulldown labeled JREs. You should find your JRE listed like JRE1.6.0.33. If not use the Installed JRE button. Select the desired JRE. Click the FINISH button. Gracefully exit, in the Server: Server Runtime Environments window, click OK in the New Server: Define a new Server window, hit NEXT in the New Server: Add and Remove Window, select apps and install them on the server. in the New Server: Add and Remove Window, click Finish

That's all. Interesting, only steps 7-10 seem to matter, and they will change the JRE used on all servers you have previously defined to use TOMCAT v7.0. The rest of the steps are just because I can't find any other way to get to the screen except by defining a new server. Does anyone else know an easier way?


I have installed tomcat 6 using an .exe file [windows service] on windows 7 os. Thus I don't see the catalina.sh file in the bin directory for tomcat. Is there any other way, where I can change the jdk version mapped to such a tomcat installation?
A
Ahmed Ashour

On Linux, Tomcat7 has a configuration file located at:

/etc/sysconfig/tomcat7

... which is where server specific configurations should be made. You can set the JAVA_HOME env variable here w/o needing to create a profile.d/ script.

This worked for me.


Not sure why the down-vote was made. A comment would be nice. Again this solution worked for me.
On which distribution of Linux did that work? I get ls: cannot access /etc/sysconfig/tomcat7: No such file or directory
Amazon Web Service AMI Linux
@kostmo Check /etc/default/tomcat7 (askubuntu.com/questions/154953/specify-jdk-for-tomcat7)
M
Michael

There are several good answers on here but I wanted to add one since it may be helpful for users like me who have Tomcat installed as a service on a Windows machine.

Option 3 here: http://www.codejava.net/servers/tomcat/4-ways-to-change-jre-for-tomcat

Basically, open tomcatw.exe and point Tomcat to the version of the JVM you need to use then restart the service. Ensure your deployed applications still work as well.


FYI: tomcatw reads its properties from the registry - e.g.: HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Apache Software Foundation\Procrun 2.0\Tomcat7\Parameters\Java
t
test

test open the termenal or cmd. go to the [tomcat-home]\bin directory. ex: c:\tomcat8\bin write the following command: Tomcat8W //ES//Tomcat8 will open dialog, select the java tap(top tap). change the Java virtual Machine value.


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now