如何更改TOMCAT使用的Java版本?
我的系统上安装了 Java 1.6 和 Tomcat 5.5。
但是 Tomcat 5.5 访问 Java 1.5,因此在使用 JSP 执行 Java 代码时,我收到错误 Bad version number in .class file
。
如何将 Tomcat 版本更改为 Java 1.6?
更新
我尝试更改 tomcat5w.exe 指向版本 1.6 的 JVM,现在我摆脱了 Bad version in .class file
错误。但现在,我收到以下错误。
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)
根本原因可能是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
当你打开catalina.sh/catalina.bat时,你可以看到:
因此,将环境变量
JAVA_HOME
设置为指向 Java 6。此外,还要确保JRE_HOME
指向相同的目标(如果已设置)。更新:由于您使用的是 Windows,请参阅此处了解如何管理环境变量
When you open catalina.sh / catalina.bat, you can see :
So, set your environment variable
JAVA_HOME
to point to Java 6. Also make sureJRE_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
您可以使用以下步骤更改 JDK 或 JRE 位置:
[ tomcat-home]\bin
目录。ex:
c:\tomcat8\bin
命令:
Tomcat8W //ES//Tomcat8
注意:
在 Apache TomEE 中的步骤相同,但步骤 (3) 命令必须是:
TomEE //ES
You can change the JDK or JRE location using the following steps:
[tomcat-home]\bin
directory.ex:
c:\tomcat8\bin
command:
Tomcat8W //ES//Tomcat8
note:
in Apache TomEE same steps, but step (3) the command must be:
TomEE //ES
如果您使用标准脚本启动 Tomcat(即您尚未将 Tomcat 安装为 Windows 服务),则可以使用 setenv.bat 文件来设置 JRE_HOME 版本。
应该就是这样了。
您可以使用 %CATALINA_BASE%\bin\configtest.bat 对此进行测试(免责声明:我仅在 Tomcat7 安装中检查过此操作)。
进一步阅读:
“高级配置 - 多个 Tomcat 实例”
使用“setenv”脚本(可选,推荐)'
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.
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:
'Advanced Configuration - Multiple Tomcat Instances'
Using the "setenv" script (optional, recommended)'
在 Eclipse 中,很容易将 Tomcat 指向新的 JVM(在本例中为 JRE6)。我的问题是我找不到在哪里做。技巧如下:
即可。有趣的是,只有步骤 7-10 似乎很重要,它们将更改您之前定义为使用 TOMCAT v7.0 的所有服务器上使用的 JRE。其余步骤只是因为除了定义新服务器之外,我找不到任何其他方法来访问屏幕。还有人知道更简单的方法吗?
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:
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?
这里有几个很好的答案,但我想添加一个,因为它可能对像我这样在 Windows 计算机上将 Tomcat 作为服务安装的用户有所帮助。
这里的选项 3: http://www.codejava .net/servers/tomcat/4-ways-to-change-jre-for-tomcat
基本上,打开 tomcatw.exe 并将 Tomcat 指向您需要使用的 JVM 版本,然后重新启动服务。确保您部署的应用程序仍然正常工作。
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.
在 Linux 上,Tomcat7 有一个配置文件,位于:
... 这是应进行服务器特定配置的位置。您可以在此处设置 JAVA_HOME 环境变量,无需创建 profile.d/ 脚本。
这对我有用。
On Linux, Tomcat7 has a configuration file located at:
... 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.
对我来说,它是从“文件”> 设置的项目结构>项目>> sdk 到正确的版本,然后在运行 Tomcat 的 Intellij 中应用并确定。
For me, it got set from File > Project Structure > Project > sdk to right version and then apply and ok in Intellij from where I was running my tomcat.
如果您使用 IDEA。
打开 Tomcat 的运行/调试配置。
并将 JRE_HOME 和 JAVA_HOME 添加到“启动”选项卡:
If you use the IDEA.
Open a run/debug configuration of Tomcat.
and to add a JRE_HOME and JAVA_HOME to the tab Startup:
测试
打开终端或cmd。
进入[tomcat-home]\bin目录。
例如:c:\tomcat8\bin
写入以下命令:Tomcat8W //ES//Tomcat8
将打开对话框,选择 java tap(top tap)。
更改 Java 虚拟机值。
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.