14

I have a JavaFX application I was migrating from Java 8 to Java 11, it has been a rough transition but most of the application is working except for the web service, it keeps giving me the exception:

Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
            at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
            at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
            at java.base/java.lang.Thread.run(Thread.java:834)
    Caused by: java.lang.NoClassDefFoundError: com/sun/org/apache/xml/internal/resolver/CatalogManager
            at com.sun.xml.ws.util.xml.XmlUtil.createDefaultCatalogResolver(XmlUtil.java:296)
            at com.sun.xml.ws.client.WSServiceDelegate.createCatalogResolver(WSServiceDelegate.java:348)
            at com.sun.xml.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:334)
            at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:292)
            at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:201)
            at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:182)
            at com.sun.xml.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:178)
            at com.sun.xml.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:89)
            at javax.xml.ws.Service.<init>(Service.java:82)
            at e.bop.asycuda.WSMrrtService.<init>(WSMrrtService.java:39)
            at e.bop.main.EBop.start(EBop.java:56)
            at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
            at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
            at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
            at java.base/java.security.AccessController.doPrivileged(Native Method)
            at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
            at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
            at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
            at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
            ... 1 more
    Caused by: java.lang.ClassNotFoundException: com.sun.org.apache.xml.internal.resolver.CatalogManager
            at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
            at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
            at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
            ... 20 more

I have looked at similar question like this but to no avail. I have the following dependancy in my pom file

  <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.3.1</version>
        <type>pom</type>
    </dependency>
Astonio
  • 635
  • 2
  • 8
  • 21

6 Answers6

22

This dependency contains the class com.sun.org.apache.xml.internal.resolver.CatalogManager that your project is not finding.

<dependency>
    <groupId>com.sun.org.apache.xml.internal</groupId>
    <artifactId>resolver</artifactId>
    <version>20050927</version>
</dependency>
Carlos
  • 1,340
  • 1
  • 10
  • 26
  • 1
    This too failed. – Astonio Oct 10 '19 at 10:30
  • this dependency should never be used/needed on Java SE 9+ – lukasj May 06 '20 at 12:50
  • @lukasj Why shouldn't it be used? On the other hand, what's the reason it can be used to avoid the NoClassDefFoundError? – Simon Jul 12 '21 at 11:02
  • @Simon It depends on whether one wants to hide or fix the bug in his own code (or in the library other than jaxws one is using, like ie Ant <1.10.6). jaxws-rt (latest versions as of today are 2.3.4 (javax)/3.0.1 (jakarta)) is a multirelease jar file and as such relies on javax.xml.catalog.Catalog on JDK 9+ through versioned classes. If versioned classes are not found, then it is definitely not a problem of jaxws but a problem of the user app/library, which is not multi-release aware instead; cause can be in using custom classloader. BTW: resolver exists to support AIX platform on JDKs <9 – lukasj Jul 13 '21 at 12:29
  • 1
    @lukasj where would a mere mortal go to learn the incantations required in gradle so that my fat-jar app will use the jdk9+ release of the multi-release dependency "com.sun.xml.ws:jaxws-rt:2.3.5"? thanks! – pabl0rg Aug 23 '21 at 15:32
  • 1
    @pabl0rg if one repackages 3rd party lib in his fat-jar, he intentionally alters its original content and does so on his own risk. I doubt one cares about properly merging content of all possibly conflicting files, such as manifests, which may contain important metadata like in case of mr jar. How can such 3rd party lib prevent user doing so? No fat-jar => no problem, for the rest, there is gradle docs, java se docs and expectation that 3rd party lib may leverage arbitrary new Java SE feature at any time (as long as at satisfies its minimum SE runtime version) - whatever that means ;-) – lukasj Aug 24 '21 at 19:22
  • @lukasj you're totally right. Most dependencies work ok in fat jars, others can be made to work using shading rules. We'll look into other ways of packaging that are simple and don't break anything. Docker containers seem to be gaining popularity in the java world, though i used to think they were overkill since we have jars. Thanks! – pabl0rg Aug 25 '21 at 20:24
  • lukasj is incorrect, this tip works and it's fine to use this in Java SE 9+ if you're using older jax-ws libraries because you're not ready to switch to jakarta package names for all of your Java EE stuff. – Jesse Barnum May 03 '23 at 02:23
13

What ended up working was adding

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.3.1</version>
    <type>pom</type>
</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-ri</artifactId>
    <version>2.3.0</version>
    <type>pom</type>
</dependency>

To my pom file.

Astonio
  • 635
  • 2
  • 8
  • 21
  • 1
    If you check the `jaxws-ri` or `jaxws.rt` contain the dependency (resolver in version 20050927) just like mentioned in the highest voted answer. – Lonzak Jun 10 '21 at 13:48
10

I had the same exceptions problems with a project after moving from Java 8 to Java 11.

These are the project settings:

  • The project is a client that access a server using soap web services
  • The web services of the server are generated via https://cxf.apache.org/ by using wsdl2java. The exception occurs by calling the generated sources
  • The project will be deployed to a standalone version by using the maven-assembly-plugin

Solution:

The only (and actually easiest) thing that worked for me was to enable multi release in the pom file:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>
                                    de.mycompany.testclient.CmdLineRunner
                                </mainClass>
                            </manifest>
                            <manifestEntries>
                                <!-- This fixed the CatalogManager exception problem -->
                                <Multi-Release>true</Multi-Release>
                            </manifestEntries>
                        </archive>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

I did not add any dependencies related to com.sun.xml.ws

Christof Nasahl
  • 229
  • 3
  • 6
  • I have the exact same scenario: I'm using VMware's VIM SDK jar for connecting to vsphere web services. I am migrating my project from java 8 to java 11. This worked. – PhoenixPerson Nov 24 '21 at 10:59
3

With java 11 we had to add this

<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.3.1</version>
</dependency>

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

<dependency>
    <groupId>javax.jws</groupId>
    <artifactId>javax.jws-api</artifactId>
    <version>1.1</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-xjc</artifactId>
    <version>2.3.2</version>
</dependency>

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.2</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.3.2</version>
</dependency>

<dependency>
    <groupId>com.sun.istack</groupId>
    <artifactId>istack-commons-runtime</artifactId>
    <version>3.0.8</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.stream.buffer</groupId>
    <artifactId>streambuffer</artifactId>
    <version>1.5.7</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>policy</artifactId>
    <version>2.7.6</version>
</dependency>
cabaji99
  • 1,305
  • 11
  • 9
1

if one gets:

   Caused by: java.lang.NoClassDefFoundError: com/sun/org/apache/xml/internal/resolver/CatalogManager
            at com.sun.xml.ws.util.xml.XmlUtil.createDefaultCatalogResolver(XmlUtil.java:296)

on Java SE 9 or newer then it is his environment being wrong. On SE 9 and newer versions it is javax.xml.catalog.CatalogManager what is supposed to by used by the class loaded from META-INF/versions folder. If you're using Ant, move to 1.10.7 or newer, in all other cases starting JVM with -Djdk.util.jar.enableMultiRelease=force may help.

lukasj
  • 126
  • 1
  • 1
0

I fixed this issue by using only

<!-- https://mvnrepository.com/artifact/com.sun.xml.ws/jaxws-rt -->
<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>jaxws-rt</artifactId>
    <version>2.3.3</version>
</dependency>

and enabling Multi-Release build in pom.xml, cf. https://stackoverflow.com/a/60742827/3906760.

MrTux
  • 32,350
  • 30
  • 109
  • 146