Search code examples
javawebspherewildflywildfly-10

Can't load class sun.net.dns.ResolverConfiguration on Wildfly (JBOSS)


I have the Java code below that works fine on a basic Main class example. Great!

However, when it's deployed on Wildfly (10.0.0) application server the mentioned class isn't found and an exception is thrown. I've tested on another application server like IBM Websphere Application (8.0 and 9.0) and it also works.

Does someone have an idea why does this happens on Wildfly?


The Code:

String resConfName = "sun.net.dns.ResolverConfiguration";
Class resConfClass = Class.forName(resConfName);

The Exception:

java.lang.ClassNotFoundException: sun.net.dns.ResolverConfiguration from [Module "deployment.myApp.ear.myApp.war:main" from Service Module Loader]

My Wildfly Environment: (sad face)

  • Wildfly 10.0.0
  • using jdk1.8.0_152

My Websphere 8 Environment: (happy face)

  • WAS 8.0.0.12
  • using jdk1.6.0_45

My Websphere 9 Environment: (happy face)

  • WAS 9.0.0.11
  • using jdk1.8.0_152

Simple main example: (happy face)

  • using jdk1.6.0_45 or jdk1.8.0_152

Thank you in advance!


Solution

  • There are some notes in the WildFly developer guide about this.

    https://docs.wildfly.org/19/Developer_Guide.html#accessing-jdk-classes

    By default, not all JDK classes are exposed to deployments. So you need to set up a system dependency in jboss-deployment-structure.xml like this.

    <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
        <deployment>
            <dependencies>
                <system export="true">
                    <paths>
                        <path name="sun/net/dns"/>
                    </paths>
                </system>
            </dependencies>
        </deployment>
    </jboss-deployment-structure>
    

    In later versions of WildFly (18, 19) this seems to be working without the need to do this.