Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 893
LGAP Avatar asked Nov 01 '10 19:11

LGAP


People also ask

Which version of Java is Tomcat using?

ya java -version says it is java 1.7.

How do I change Tomcat version?

High level steps: Project Properties / Target Runtime / select the Target runtime. Project Properties / Java Build Paths / Edit Apache Tomcat entry and select the run time to add to classpath. Project Properties / Project Facets / Select Dynamic Web Module and change the version.

How do I change the Java path in Tomcat 9?

Using setenv file. In CATALINA_BASE/bin directory open or create file named setenv.sh and put JAVA_HOME=/usr/lib/jvm/openjdk-8-jdk in it. This will change it only for your tomcat. Please note to change it to the JDK/JRE you want to use.


2 Answers

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

like image 102
Bozho Avatar answered Sep 21 '22 07:09

Bozho


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

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

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

like image 33
Hazim Avatar answered Sep 19 '22 07:09

Hazim