Search code examples
javahibernatetomcatxamppstartup

could not create the Java Virtual Machine while running tomcat


i have a presentation about hibernate and to do an example i needed tomcat after installing tomcat 10 i tried to start it up using this command C:\tomcat\bin>startup below is the result I get when i run it

C:\tomcat\bin>startup
Using CATALINA_BASE:   "C:\tomcat"
Using CATALINA_HOME:   "C:\tomcat"
Using CATALINA_TMPDIR: "C:\tomcat\temp"
Using JRE_HOME:        "C:\Program Files\Java\jre1.8.0_361"
Using CLASSPATH:       "C:\tomcat\bin\bootstrap.jar;C:\tomcat\bin\tomcat-juli.jar"
Using CATALINA_OPTS:   ""

but window pops up for a split of a second and goes away.

so i tried the following command to see what's going on C:\tomcat\bin>catalina.bat run here is the results

Using CATALINA_BASE:   "C:\tomcat"
Using CATALINA_HOME:   "C:\tomcat"
Using CATALINA_TMPDIR: "C:\tomcat\temp"
Using JRE_HOME:        "C:\Program Files\Java\jre1.8.0_361"
Using CLASSPATH:       "C:\tomcat\bin\bootstrap.jar;C:\tomcat\bin\tomcat-juli.jar"
Using CATALINA_OPTS:   ""
Unrecognized option: --add-opens=java.base/java.lang=ALL-UNNAMED
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

btw here are the envirment variables .. because i saw many trying having the problem there .. but i dont think it's my case enter image description here enter image description here

N.B. tomcat version 10.1.7 JDK 17 jre-8u361

i had many problem before this that i tried to solve, some of them did and some not , always a problem leads me to another , i used to have error 500 Internal Server Error aloot while trying to follow a tutorial.

i dont know if this may be a help or not but i used to have another problem that i think i already solved which is i had xampp running tomcat too , meaning i had an old version on xampp and i instaled a new one, then i deleted the new one and replace new tomcat version instead in xampp, and deleted the service so it can be created from new ;

**but after all nothing succeded so i uninstalled xampp, tomcat and java , and started from new. **


Solution

  • The problem is, Tomcat using Java 8 version which does not support --add-opens option. This option introduced in Java 9.

    Update
    Thanks to Olaf's comment I redefine the previous sentence. However Tomcat 10.0.x used to support Java 8 it was dropped in 10.1.0 which requires Java 11 at least.

    A Java Runtime Environment required by Apache Tomcat. Older Java versions shipped multiple artifacts JRE only and JDK. For now it had changed. When Tomcat starts it will try to evaulate installed runtime environment based on environment variables.

    If JRE_HOME is set then it will be used.
    If JRE_HOME is not set but JAVA_HOME is set then Tomcat startup script will automatically set JRE_HOME based on JAVA_HOME vaule.
    If both JRE_HOME and JAVA_HOME is set then JRE_HOME will be used.

    As the question describes both environment variable is set, so JRE_HOME will be used. But JRE_HOME points to Java 8.

    You can customize JRE_HOME (set to new Java version) or you also can remove this environment variable and use JAVA_HOME as I described previously.