Search code examples
javamavenjax-ws

ClassNotFoundException: javax.xml.ws.Endpoint despite having the correct(?) maven dependency and only in CLI


I am having troubles bringing a WebService back online. It was not a Maven Project till now, but I decided to move on an bring it in shape with Maven dependencies. Before that point all of the dependencies were copied manually. So my pom.xml looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.iifleuchten.auth.webservice</groupId>
    <artifactId>AuthService</artifactId>
    <version>0.9</version>
    <name>AuthService</name>
    <properties>
        <maven.compiler.source>1.6</maven.compiler.source>
        <maven.compiler.target>1.6</maven.compiler.target>
    </properties>
    <dependencies>
        <!-- jax-ws maven dependency -->
        <dependency>
            <groupId>javax.xml.ws</groupId>
            <artifactId>jaxws-api</artifactId>
            <version>2.3.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.ws</groupId>
            <artifactId>jaxws-rt</artifactId>
            <version>2.1.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.jws/javax.jws-api -->
        <dependency>
            <groupId>javax.jws</groupId>
            <artifactId>javax.jws-api</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.xml.messaging.saaj</groupId>
            <artifactId>saaj-impl</artifactId>
            <version>1.5.1</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.iifleuchten.auth.webservice.AuthPublisher</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

I am using eclipse, and I can run the webservice inside eclipse. It works and the service is available (tested with another small program within the same project, which calls the local webservice) although I do get a warning when running the service:

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1 (file:/home/manoca/.m2/repository/com/sun/xml/bind/jaxb-impl/2.1.6/jaxb-impl-2.1.6.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

When I do the maven install thing via the eclipse context menu the build works fine and the jar gets created. However, this jar does not work in the cli when calling it like java -jar AuthService.jar. I get a class not found exception there. He can't find the Endpoint class:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/ws/Endpoint

here's the code, where it stumbles upon:

Endpoint.publish("http://0.0.0.0:7779/ws/auth", authImpl);

I think other classes from for example the javax.jws package do work, as all the implementation of the WebService stuff and the corresponding annotations should "happen" before it comes to the Endpoint.publish and this does not cause any exceptions? Long story short: this are my first Maven related experiments and after a few hours now, I am really out of ideas what to do. Any suggestions are highly appreciated ;)


Solution

  • Thanks a lot for the hint. I do begin to understand the whole deal a lot more now. This link really has some good information although I was just stupid in the first place: https://medium.com/@randilfernando/when-to-use-maven-jar-maven-assembly-or-maven-shade-ffc3f76ba7a6