2

Fairly new to Webservices, have done some research and generated client stubs for a third party WSDL using JAX-WS RI (wsimport tool). JDK 8 is being used. Using generated Stubs, web service client is written to invoke the WSDL operations. Maven Build is successful but while testing it, getting "java.lang.NoClassDefFoundError: javax/xml/ws/Service".

Here is the Web service client. Tried to refer many resources for NoClassDefFoundError as well, but nothing actually worked. While debugging understood its failing in line-11 below. How to fix this NoClassDefFoundError, please Help?

line-11:  ServiceWS service = new ServiceWS(); //@WebServiceClient
line-12:  ServiceWSSoap stubWS = service.getServiceWSSoap(); //where ServiceWSSoap is @WebService and getServiceWSSoap() is @WebEndpoint 

Here is the Stack trace

java.lang.NoClassDefFoundError: javax/xml/ws/Service
    at package1.ProjectClient.getStub(ProjectClient.java:11)
    at package.Project.<init>(Project.java:55)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.base/java.lang.Class.newInstance(Unknown Source)
    at package.SubClass.getInstance(SubClass.java:1284)
    at package.SubClass.getCall(SubClass.java:635)
    at package.SubClass.execute(SubClass.java:317)
    at package.MainClass.run(MainClass.java:1216)
    at package.MainClass.execute(MainClass.java:759)
    at package.ServerClass.b(ServerClass.java)
    at package.ServerClass.run(ServerClass.java)
    at java.base/java.lang.Thread.run(Unknown Source)

I have included jaxws-api dependency in my pom.xml, but still no luck

 <dependency>
        <groupId>javax.xml.ws</groupId>
        <artifactId>jaxws-api</artifactId>
        <version>2.3.1</version>
    </dependency>

Research links: 1) Java Webservice Client (Best way)
2) https://mkyong.com/webservices/jax-ws/jax-ws-wsimport-tool-example/
3) https://mkyong.com/webservices/jax-ws/jax-ws-hello-world-example/

Java3
  • 21
  • 1
  • 1
  • 3

3 Answers3

1

You have included only API classes. Your project needs also some Implementation classes (artifact). One of possible implementations is jaxws-ri:

<dependency>
  <groupId>com.sun.xml.ws</groupId>
  <artifactId>jaxws-ri</artifactId>
  <version>2.3.1</version>
</dependency>
Volo Myhal
  • 74
  • 5
1

Running from Command Line

I encountered this when running wsdl2java directly from command line (on my mac). The wsdl2java script is not very smart, so you have to help it a bit.

After you download the CXF tools from the apache website, you should specify their location before running the executables.

export CXF_HOME=/Users/dimitar/Downloads/apache-cxf-4.0.0
export CLASSPATH=$CLASSPATH:$CXF_HOME/lib/*
export PATH=$PATH:$CXF_HOME/bin
dzlatkov
  • 646
  • 6
  • 7
0

Thanks for your response Volo Myhal. I have already included jaxws-rt dependency as well. But still I keep getting NoClassDefFoundError.

This issue is resolved after manually adding the required jars into our local server path from the .m2 folder

Java3
  • 21
  • 1
  • 1
  • 3