8

The specific error I am facing when starting my app on Tomcat9. Spring version: 5.1.5.RELEASE:

SEVERE: Error configuring application listener of class [org.springframework.web.context.request.RequestContextListener] java.lang.NoClassDefFoundError: javax/xml/ws/WebServiceRef

There are multiple answers on this error that all suggest adding maven dependencies. I have added these dependencies:

POM.xml

My build path:

enter image description here

The WebServiceRef class is found in the package explorer:

enter image description here

This error shows in the console when starting the app on Tomcat9. Here is more of the stack trace: enter image description here

SEVERE: Error configuring application listener of class [org.springframework.web.context.request.RequestContextListener] java.lang.NoClassDefFoundError: javax/xml/ws/WebServiceRef at org.apache.catalina.core.DefaultInstanceManager.populateAnnotationsCache(DefaultInstanceManager.java:303) ...more stuf.... java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:355) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:495)

Any help or suggestions would be much appreciated!

Update 1: Here are some .jar files that get copied into the final .war build under WEB-INF/lib. The 4 new maven dependencies and their versions are here, but there is also possible duplicate .jar files.

enter image description here

Update 2: Copying the jaws-api jar directly into my Tomcat Classpath resolved the runtime error... So the app is launching now, but how would I overcome this issue when actually deploying the .war file?

enter image description here

Adam
  • 490
  • 7
  • 21
  • Could you please show your effective `pom.xml` via `mvn help:effective-pom`? – mle Mar 25 '19 at 21:34
  • It's pretty big, is there something you are specifically looking for in there? – Adam Mar 25 '19 at 21:41
  • 1
    I am looking for overrides which lead to a state in that your jaxb do not make their way into the final `*.jar` or `*.war*`. Could you cross-check if your above mentioned dependencies are really present in you finally bundled/packaged artifact? – mle Mar 25 '19 at 21:44
  • 1
    I've updated my questions with a screenshot showing some of what gets copied over to the .war file after a build. – Adam Mar 25 '19 at 21:56
  • 1
    Well... that's looking good. Next approach: try to copy the four mentioned libs directly into the `lib` folder of your Tomcat and see what is happening. – mle Mar 25 '19 at 22:07
  • This resolved the error, I updated my question. So for a dev environment this is a work-around, how would I overcome this issue when actually deploying? Thanks. – Adam Mar 26 '19 at 16:02
  • Duplicate of [*Replacements for deprecated JPMS modules with Java EE APIs*](https://stackoverflow.com/q/48204141/642706) – Basil Bourque Mar 28 '19 at 01:27
  • Please replace `...more stuf....` by the actual stack trace. Which exact Tomcatversion is it? Are you using JNDI or other resources managed by Tomcat? – Selaron Mar 28 '19 at 07:56
  • @BasilBourque It's not a duplicate because the issue was not resolved with just adding the dependencies as suggested. Please see Update#2 for the work-around I am using currently. However this is not a long term solution. – Adam Mar 28 '19 at 13:27
  • You say that there may be duplicated JARS; are you sure there are no duplicated jars? If there are duplicated jars, try to remove them (I suggest to you to remove them from WEB-INF/lib of the final artifact and then to modify the pom.xml) – Angelo Immediata Mar 28 '19 at 13:39

2 Answers2

2

This issue came down to Docker Desktop (Windows) interfering with Tomcat and specifically Tomcat's admin port 8006, which forced me to change the port number to allow Tomcat to launch (from 8006 to 8007 for example). I had an old Tomcat container at one point in time, and this may have been fired up when my computer started via Docker Desktop without me realizing it.

Steps completed to fix the issue assuming your pom.xml has the necessary dependencies.

  1. Stop Docker Desktop
  2. Use the latest JDK11 build and update JAVA_HOME as needed
  3. Restore default Tomcat admin server port to 8006
  4. Republish/Restart the Tomcat server

I think in most cases this issue will be resolved as explained here from updating the pom.xml with the needed dependencies. In my case it was entirely environmental and for some reason Docker Desktop prevented Tomcat from accessing the jaws-api-2.3.1.jar file at runtime. Tomcat's inability to access this .jar file was confirmed via my 'Update 2' in the question above.

My pom.xml ended up only needing the following items: enter image description here

Adam
  • 490
  • 7
  • 21
1

Try by using this dependency in your pom.xml:

<dependency>
    <groupId>javax.annotation</groupId>
    <artifactId>javax.annotation-api</artifactId>
    <version>1.3.2</version>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.4.0-b180725.0427</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.4.0-b180725.0644</version>
</dependency>

I just tried and it works with tomcat 9 and spring 5.1.5

Angelo Immediata
  • 6,635
  • 4
  • 33
  • 65
  • The jaxb-api version was not found, I updated it to: 2.4.0-b180830.0359. Also, the jaxb-runtime was not found (build error), so I updated that to 2.4.0-b180830.0438 per the latest builds on Maven Central. The same error is showing at runtime: javax/xml/ws/WebServiceRef. – Adam Mar 28 '19 at 18:40
  • that's strange because i tried it before to answer; i can find them here [jaxb-api](https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api/2.4.0-b180725.0427) and [jaxb-runtime](https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime/2.4.0-b180725.0644) – Angelo Immediata Mar 28 '19 at 18:42
  • Yeah, here are the latest. jaxb-runtime and api: https://mvnrepository.com/artifact/org.glassfish.jaxb/jaxb-runtime. https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api – Adam Mar 28 '19 at 18:45
  • well i guess there is something wrong in your classpath – Angelo Immediata Mar 28 '19 at 19:02