Reputation: 101
I'm trying to deploy a simple java servlet to Tomcat, one that consumes a web-service which is deployed to same Tomcat on localhost. I'm working with a Maven project in Netbeans.
The servlet imports the following classes:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.WebServiceRef;
I'm able to deploy the generated war file to Tomcat, but i fail to start the application with the following errors in catalina.out:
28-Mar-2020 20:57:12.769 SEVERE [http-nio-8080-exec-93] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive [/opt/tomcat/apache-tomcat-9.0.31/webapps/CalculatorWebServiceClient.war]
java.lang.IllegalStateException: Error starting child
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:720)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:690)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:705)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:978)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:493)
at org.apache.catalina.startup.HostConfig.check(HostConfig.java:1642)
at jdk.internal.reflect.GeneratedMethodAccessor66.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.tomcat.util.modeler.BaseModelMBean.invoke(BaseModelMBean.java:289)
at java.management/com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:809)
at java.management/com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801)
at org.apache.catalina.manager.ManagerServlet.check(ManagerServlet.java:1590)
at org.apache.catalina.manager.HTMLManagerServlet.upload(HTMLManagerServlet.java:294)
at org.apache.catalina.manager.HTMLManagerServlet.doPost(HTMLManagerServlet.java:212)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:660)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
...
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/CalculatorWebServiceClient]]
at org.apache.catalina.util.LifecycleBase.handleSubClassException(LifecycleBase.java:440)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:198)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:717)
... 43 more
Caused by: java.lang.TypeNotPresentException: Type javax.jws.WebService not present
at java.base/sun.reflect.annotation.TypeNotPresentExceptionProxy.generateException(TypeNotPresentExceptionProxy.java:46)
at java.base/sun.reflect.annotation.AnnotationInvocationHandler.invoke(AnnotationInvocationHandler.java:86)
at com.sun.proxy.$Proxy2.value(Unknown Source)
at org.apache.catalina.startup.ContextConfig.processServletContainerInitializers(ContextConfig.java:1699)
at org.apache.catalina.startup.ContextConfig.webConfig(ContextConfig.java:1137)
at org.apache.catalina.startup.ContextConfig.configureStart(ContextConfig.java:774)
at org.apache.catalina.startup.ContextConfig.lifecycleEvent(ContextConfig.java:301)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:123)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5051)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
... 44 more
Caused by: java.lang.ClassNotFoundException: javax.jws.WebService
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1365)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1188)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at java.base/sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
I have noticed the ClassNotFoundException: javax.jws.WebService in the log file and edited the pom.xml file to include:
javax.xml.ws.jaxws-api.2.3.1
and also its compile dependencies as found per [https://mvnrepository.com/artifact/javax.xml.ws/jaxws-api/2.3.1/][1]:
javax.annotation.javax.annotation-api.1.3.2
javax.xml.bind.jaxb-api.2.3.1
javax.xml.soap.javax.xml.soap-api.1.4.0
When inspecting the project directory i can see that the correspondig libraries are present in WEB-INF/lib directory.
Even after this I keep getting the same error message and cannot start the application. Could somebody tell me what i'm missing here?
Kind regards, Michal
Upvotes: 6
Views: 17199
Reputation: 11
This JAR solved similar issue for me.
<dependency>
<groupId>jakarta.jws</groupId>
<artifactId>jakarta.jws-api</artifactId>
<version>2.1.0</version>
</dependency>
Upvotes: 1
Reputation: 19
I had the same problem and changed in IDE used Java version from 11 to 8, plus set my Maven to 3.3.9 and "ClassNotFoundException: javax.jws.WebService" problem was solved for me.
Upvotes: 1
Reputation: 144
If you are using java 11 then you must receive this erorr as no more JAXB( javax.xml.bind does not exist any more in java 11)
Add below dependencies in your pom file to resolve this.
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.1</version>
</dependency>
Upvotes: 1