23

Unable to start tomcat based app with java 9 because of default "java.endorsed.dirs" option in catalina.sh.

-Djava.endorsed.dirs=/usr/local/share/tomcat/endorsed is not supported. Endorsed standards and standalone APIs in modular form will be supported via the concept of upgradeable modules. 
Error: Could not create the Java Virtual Machine. 
Error: A fatal exception has occurred. Program will exit.

Is there a work around for this?

learner
  • 1,952
  • 7
  • 33
  • 62
  • 1
    Well, looking for a solution to [this SO question](https://stackoverflow.com/questions/45791676/specific-collection-type-returned-by-convenience-factory-method-in-java-9), I had realized and raised [another SO](https://stackoverflow.com/questions/45802981/unable-to-process-file-module-info-class-within-a-java9-project-results-in-class), which all boilled down to the point that with java 9, you need to use Tomcat 9 for adaptibility reasons. In short try out executing your application with `apache-tomcat-9.0.0.M26` and `jdk-9+181` to figure out exact failures . – Naman Aug 28 '17 at 11:06

8 Answers8

29

You'll have to hack the script bin/catalina.sh to get this to work.

There are a bunch of lines like this in bin/catalina.sh:

  exec "$_RUNJDB" "$LOGGING_CONFIG" $LOGGING_MANAGER $JAVA_OPTS $CATALINA_OPTS \
    -Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath "$CLASSPATH" \
    ...

Just remove the second of those lines (the one with -Djava.endorsed.dirs) in each case and you should be back in business.

I'm looking at improving those scripts so that -Djava.endorsed.dirs is not provided to the JVM when the value is empty (which should be the case if you are using Java 9).

UPDATE 2017-11-06

Looks like r1810284 should fix the endorsed.dirs problem. Expect this fix to be included in Tomcat 7.0.83 (or whatever the next 7.0.x version passes voting).

UPDATE 2018-03-07

The first official release of Apache tomcat 7.0.x that includes this fix is Apache Tomcat 7.0.84, voted stable on 2018-01-24.

Christopher Schultz
  • 20,221
  • 9
  • 60
  • 77
  • a similar check was implemented by the WTP folks at https://bugs.eclipse.org/bugs/show_bug.cgi?id=507338 If you have not already changed `catalina.sh`, I can volunteer a patch for it. – Kilokahn Oct 20 '17 at 01:59
  • @Kilokahn Patches always welcome! Post to users list or fork+PR on Github. – Christopher Schultz Oct 20 '17 at 13:42
  • I have added a PR on github - https://github.com/apache/tomcat70/pull/13 – Kilokahn Oct 20 '17 at 20:40
  • I took back the PR because the latest code seems to take care of it already. When can we expect the next 7.x release? – Kilokahn Oct 23 '17 at 15:45
  • @Kilokahn Thanks for the contribution, anyway. Feel free to make additional PRs against Tomcat or any other ASF project. Bugzilla is a good place to find low-hanging fruit which we intentionally leave available as introductions for new contributors. Join the user and dev mailing lists if you'd like to get more involved. – Christopher Schultz Oct 23 '17 at 17:32
  • Still a problem in Tomcat 7.0.82. – vadipp Nov 03 '17 at 13:08
  • Looks like [r1810284](http://svn.apache.org/viewvc?view=revision&revision=1810284) should have fixed the `endorsed.dirs` problem. Tomcat 7.0.82 was released as [r1810087](http://svn.apache.org/viewvc?view=revision&revision=1810087) so I think this fix simply hasn't yet been released. – Christopher Schultz Nov 06 '17 at 15:30
  • I am just wondering if there is any recommendation from tomcat vendor to not use tomcat 7 with java 9. – learner Mar 23 '18 at 04:30
  • There is no particular reason not to use Tomcat 7 on Java 9. If you find that something is not working, please report it on the Tomcat users' mailing list and it should be corrected. – Christopher Schultz Mar 23 '18 at 13:30
  • On the other hand, if you are aggressively moving towards Java 9, why not also consider upgrading to Tomcat 8.5 or Tomcat 9? – Christopher Schultz Mar 23 '18 at 13:32
  • Can anybody tell me, is planned TomEE version with this Tomcat patches?. My goal is production (more or less) quality package, cannot administer manually multiple installations. – Jacek Cz Apr 14 '18 at 12:36
  • @JacekCz You'd have to ask the TomEE community. Best place is their users' mailing list. – Christopher Schultz Apr 15 '18 at 15:12
  • I had this issue upgrading our Jenkins server from java 8 to open jdk11. Fix worked perfect for us. – Upen Dec 17 '19 at 22:31
4

The above issue was fixed with the later releases of Eclipse but Unfortunately, it appeared again with the release of Java 10. Here is my research : Initially, I installed Java 10 and Eclipse Oxygen 3 which gave me the same error you mentioned in your question. But, at the moment I installed Java 9 and pointed my Apache tomcat runtime server to it, the error was gone.

2

In my case, what I did to answer the problem of Tomcat not running was to set Tomcat (version 7) with a lower Java version (e.g. Java 8).

Then, in startup.sh, shutdown.sh and catalina.sh I added the following:

export JAVA_HOME=`/usr/libexec/java_home -v 1.8`;
António Ribeiro
  • 4,129
  • 5
  • 32
  • 49
purpleByte
  • 21
  • 2
  • I want to run with java9+ version and hence this solution will not work for me but as we are editing catalina.sh then we can simply add code to remove endorsed dir property completely as suggested above. – learner Feb 16 '18 at 09:01
  • thank you, I just did this a couple of minutes ago, the above comment is out of my league(sorry)...I just leave my comment for those who just upgraded their java version to 9 and find their tomcat7 not working... – purpleByte Feb 16 '18 at 09:07
  • 1
    It would be better to modify (or create, if it doesn't exist) `conf/setenv.sh` instead of modifying any of the scripts that ship with Tomcat. – Christopher Schultz Jul 21 '18 at 21:43
2

To fix this bug, you need to install/update the Eclipse Web Tools Platform (WTP) to version 3.9.4 or later.

Select Help > Install new Software... Select or add following URL: http://download.eclipse.org/webtools/repository/oxygen Check Web Tools Platform (WTP) 3.9.4 Select "Next" and follow instructions

Reconfigure the tomcat in eclipse.

Matthias
  • 7,432
  • 6
  • 55
  • 88
Amit Tyagi
  • 21
  • 1
2

This symptom can come about if you have a Tomcat Runtime using a JRE earlier than Java 9 and create and run a server with that runtime. Then edit the Tomcat Runtime to use Java 9 and try to start the server. What happens is that a "-Djava.endorsed.dirs" argument gets added to the launch configuration when the server was run with the earlier JRE. When running the server after the switch to Java 9, the "-Djava.endorsed.dirs" argument is seen as a user added VM argument and kept, resulting in the error.

The simplest way to fix is to recreate the server. You can also right click on the server in the servers view and select Open. In the window that opens, click the "Open launch configuration" link at the bottom of the General section. In the dialog that opens, switch to the Arguments tab and in the "VM arguments" section, edit out the "-Djava.endorsed.dirs" argument and click OK. You should be able to start the server now.

Sri
  • 31
  • 1
1

In Run configurations -> Arguments -> VM arguments try removing

-Djava.endorsed.dirs="C:\Program Files\Apache Software Foundation\Tomcat 8.5\endorsed"

Chris Catignani
  • 5,040
  • 16
  • 42
  • 49
jyotinadda
  • 51
  • 3
0

You have to remove -

"-Djava.endorsed.dirs="/home/ttlaptop/Downloads/apache-tomcat-7.0.105/endorsed"

from run configurations, and then tomcat will start

Derrick
  • 3,669
  • 5
  • 35
  • 50
-2

I can't be sure but ..

Step 1 -- > it worked for me, I just remove servers from eclipse

Step 2 --> restarted and add server again (tomcat 7) Tomcat v7.0 Server at localhost

Vinod Joshi
  • 7,696
  • 1
  • 50
  • 51