How to change Java version used by TOMCAT?

前端 未结 7 951
时光说笑
时光说笑 2020-11-27 18:40

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 f

相关标签:
7条回答
  • 2020-11-27 18:44

    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

    0 讨论(0)
  • 2020-11-27 18:49

    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)'
    0 讨论(0)
  • 2020-11-27 18:49

    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:

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

    0 讨论(0)
  • 2020-11-27 18:54

    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.

    0 讨论(0)
  • 2020-11-27 18:59

    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

    0 讨论(0)
  • 2020-11-27 19:03

    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.

    0 讨论(0)
提交回复
热议问题