1 2 3 Previous Next 42 Replies Latest reply on Jun 24, 2016 9:02 PM by Bar Mid

    WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom

    Bar Mid Newbie

      Newbie to WildFly

      WildFly 10.0

      JDK 1.8

      Win 8

      Eclipse Luna

       

      I'm converting a Glassfish 4.0 app to WildFly 10 and running into all sorts of problems. I finally gave up on trying to configure it to use log4j. Now, I'm getting deployment issues where WildFly class loader appears to ignore jars I have listed in my pom.

       

      stack trace

      17:44:09,626 WARN  [org.jboss.modules] (Weld Thread Pool -- 3) Failed to define class com.meritagesystems.codecompliance.common.MultiLineToStringStyle in Module "deployment.CodeComplianceServices.war:main" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link com/meritagesystems/codecompliance/common/MultiLineToStringStyle (Module "deployment.CodeComplianceServices.war:main" from Service Module Loader): org/apache/commons/lang3/builder/ToStringStyle

        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

        at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

        at java.lang.reflect.Constructor.newInstance(Constructor.java:422)

        at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:446)

        at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:274)

        at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:78)

        at org.jboss.modules.Module.loadModuleClass(Module.java:605)

        at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)

        at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)

        at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)

        at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)

        at org.jboss.as.weld.WeldModuleResourceLoader.classForName(WeldModuleResourceLoader.java:68)

        at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadClass(AnnotatedTypeLoader.java:65)

        at org.jboss.weld.bootstrap.AnnotatedTypeLoader.loadAnnotatedType(AnnotatedTypeLoader.java:60)

        at org.jboss.weld.bootstrap.FastAnnotatedTypeLoader.loadAnnotatedType(FastAnnotatedTypeLoader.java:96)

        at org.jboss.weld.bootstrap.BeanDeployer.addClass(BeanDeployer.java:97)

        at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:65)

        at org.jboss.weld.bootstrap.ConcurrentBeanDeployer$1.doWork(ConcurrentBeanDeployer.java:62)

        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:63)

        at org.jboss.weld.executor.IterativeWorkerTaskFactory$1.call(IterativeWorkerTaskFactory.java:56)

        at java.util.concurrent.FutureTask.run(FutureTask.java:266)

        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

        at java.lang.Thread.run(Thread.java:745)

        at org.jboss.threads.JBossThread.run(JBossThread.java:320)

       

      pom.xml

      <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

        <modelVersion>4.0.0</modelVersion>

        <groupId>com.meritagesystems.codecompliance.rws</groupId>

        <artifactId>CodeComplianceServices</artifactId>

        <version>0.0.1-SNAPSHOT</version>

        <packaging>war</packaging>

        <name>CodeComplianceServices</name>

        <url>http://maven.apache.org</url>

        <properties>

        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <!-- BEGIN Careful not to break this version dependency -->

        <powermock.version>1.6.4</powermock.version>

        <mockito.version>1.10.19</mockito.version>

        <!-- END Careful not to break this version dependency -->

        <jackson.version>2.7.4</jackson.version>

        <hibernate.version>4.3.11.Final</hibernate.version>

        <jboss.bom.version>1.0.0.Final</jboss.bom.version>

        <wildfly.version>10.0.0.Final</wildfly.version>

        </properties>

        <dependencyManagement>

        <dependencies>

        <dependency>

        <groupId>org.wildfly.bom</groupId>

        <artifactId>wildfly-javaee7</artifactId>

        <scope>import</scope>

        <type>pom</type>

        <version>${wildfly.version}</version>

        </dependency>

        <dependency>

        <groupId>org.jboss.bom</groupId>

        <artifactId>jboss-javaee-6.0-with-tools</artifactId>

        <version> ${jboss.bom.version}</version>

          <type>pom</type>

        <scope>import</scope>

        </dependency>

        <dependency>

        <groupId>org.jboss.bom</groupId>

        <artifactId>jboss-javaee-6.0-with-hibernate</artifactId>

        <version> ${jboss.bom.version} </version>

        <type>pom</type>

        <scope>import</scope>

        </dependency>

        </dependencies>

        </dependencyManagement>

        <dependencies>

          <dependency>

        <groupId>junit</groupId>

        <artifactId>junit</artifactId>

        <version>4.12</version>

        </dependency>

        <dependency>

        <groupId>org.powermock</groupId>

        <artifactId>powermock-api-mockito</artifactId>

        <version>${powermock.version}</version>

        <scope>test</scope>

        </dependency>

        <dependency>

        <groupId>org.powermock</groupId>

        <artifactId>powermock-module-junit4</artifactId>

        <version>${powermock.version}</version>

        </dependency>

        <dependency>

        <groupId>org.mockito</groupId>

        <artifactId>mockito-all</artifactId>

        <version>${mockito.version}</version>

        </dependency>

        <dependency>

          <groupId>org.apache.commons</groupId>

          <artifactId>commons-lang3</artifactId>

          <version>3.4</version>

        </dependency>

        <dependency>

        <groupId>com.fasterxml.jackson.datatype</groupId>

        <artifactId>jackson-datatype-jsr310</artifactId>

          <version>${jackson.version}</version>

        </dependency>

        <dependency>

        <groupId>com.fasterxml.jackson.core</groupId>

        <artifactId>jackson-annotations</artifactId>

          <version>${jackson.version}</version>

        </dependency>

        <dependency>

        <groupId>com.fasterxml.jackson.jaxrs</groupId>

        <artifactId>jackson-jaxrs-json-provider</artifactId>

          <version>${jackson.version}</version>

        </dependency>

        <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>hibernate-core</artifactId>

        <version>${hibernate.version}</version>

        </dependency>

        <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>hibernate-validator</artifactId>

        <version>5.2.3.Final</version>

        <scope>provided</scope>

          </dependency>

        <dependency>

        <groupId>org.hibernate</groupId>

        <artifactId>hibernate-ehcache</artifactId>

        <version>${hibernate.version}</version>

        </dependency>

        <dependency>

        <groupId>mysql</groupId>

        <artifactId>mysql-connector-java</artifactId>

        <version>5.1.38</version>

        </dependency>

        <dependency>

        <groupId>commons-beanutils</groupId>

        <artifactId>commons-beanutils</artifactId>

        <version>1.9.2</version>

        </dependency>

        <dependency>

        <groupId>org.apache.commons</groupId>

        <artifactId>commons-lang3</artifactId>

        <version>3.4</version>

        </dependency>

        </dependencies>

        <build>

        <plugins>

        <plugin>

        <!--

        The Maven Surefire plugin tests your application.

        Here we ensure we are using a version compatible with

        Arquillian

        -->

        <artifactId>maven-surefire-plugin</artifactId>

        <version>2.17</version>

        </plugin>

        <!-- The WildFly Maven Plugin deploys your war to a local WildFly container -->

        <!-- To use, set the JBOSS_HOME environment variable and run:

        mvn package wildfly:deploy -->

        <plugin>

        <groupId>org.wildfly.plugins</groupId>

        <artifactId>wildfly-maven-plugin</artifactId>

        <version>1.0.2.Final</version>

        </plugin>

        <plugin>

        <groupId>org.apache.maven.plugins</groupId>

        <artifactId>maven-war-plugin</artifactId>

        <version>2.6</version>

        <configuration>

        <failOnMissingWebXml>false</failOnMissingWebXml>

        <archive>

                    <manifestEntries>

                      <Dependencies>org.apache.commons.lang3</Dependencies>

                    </manifestEntries>

                </archive>

        </configuration>

        </plugin>

        </plugins>

        </build> 

        <repositories>

        <repository>

        <id>my-repo1</id>

        <name>my custom repo</name>

        <url>http://mvnrepository.com/</url>

        </repository>

        </repositories>

      </project>

       

      Any ideas about what I'm doing wrong?

        • 1. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
          Nicklas Karlsson Master

          Show the list of jar:s that actually are included in the WAR lib folder. Also, you are listing a dependency in the manifest to a commons lang3 module? Is there such a module defined?

          • 2. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
            Bar Mid Newbie

            Yes, it is listed in the pom:

            <dependency>

              <groupId>org.apache.commons</groupId>

              <artifactId>commons-lang3</artifactId>

              <version>3.4</version>

              </dependency>

             

            The war contains commons-lang3-3.4.jar in the WEB-INF/lib directory.

             

            The manifest contains:

            Manifest-Version: 1.0

            Built-By: b

            Build-Jdk: 1.8.0_91

            Created-By: Maven Integration for Eclipse

            Dependencies: org.apache.commons.lang3

            • 3. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
              Bar Mid Newbie

              One thing that really puzzles me is why I have to list commons.lang3 anywhere other than the POM. Is the following superfluous?

              <archive>

                <manifestEntries>

                <Dependencies>org.apache.commons.lang3</Dependencies>

                </manifestEntries>

              </archive>

              • 4. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                James Perkins Master

                If you're including commons.lang3 in your deployment you don't need to include the manifest entry. You also have it defined twice in your pom. You might want to examine your WAR and ensure the library is in the WAR/WEB-INF/lib directory.

                 

                --

                James R. Perkins

                • 5. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                  James Perkins Master

                  OT for the actual question, but configuring log4j should be pretty easy. You just need to include a log4j configuration file and ensure you don't include the log4j.jar. What kind of issues were you having with that?

                   

                  --

                  James R. Perkins

                  • 6. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                    Bar Mid Newbie

                    I removed the dupl lang3 dependency and the manifest stanza from the pom, however, that appears to have just moved the problem, not resolved it.

                     

                    16:51:45,970 WARN  [org.jboss.modules] (Weld Thread Pool -- 1) Failed to define class com.meritagesystems.codecompliance.common.MultiLineToStringStyle in Module "deployment.CodeComplianceServices.war:main" from Service Module Loader: java.lang.NoClassDefFoundError: Failed to link com/meritagesystems/codecompliance/common/MultiLineToStringStyle (Module "deployment.CodeComplianceServices.war:main" from Service Module Loader): org/apache/commons/lang3/builder/ToStringStyle

                    • 7. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                      Bar Mid Newbie

                      I am assuming the dependencies described in the POM are read and reflected in the WildFly deployment when deploying from Eclipse. However, this error is making me question that assumption. I'm wondering if I have to manually define these dependencies in the modules directory.

                      • 8. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                        James Perkins Master

                        I'm not too familiar with how eclipse builds the archive to be honest. One option is to test it from the command like since you have the maven plugin defined. If it works then we know that eclipse is not building it correctly for some reason.

                         

                        If you have WildFly already running just do

                        mvn clean wildfly:deploy
                        

                         

                        If WildFly is not running just do

                        mvn clean wildfly:run
                        

                         

                        CTRL+C can be used to terminate the run or issues a CLI shutdown which should also terminate it.

                         

                        --

                        James R. Perkins

                        • 10. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                          James Perkins Master

                          I'm purely making some guesses because I'm not sure what is required by your source code. However I've take your pom.xml and modified it to mostly mark dependencies as provided.

                           

                          I removed the hibernate-ehcache because I wasn't quite sure what you were using that for. All other Hibernate dependencies were marked as provided as were all the Jackson2 dependencies. I did however have to include the Jackson JSR-310 module in the compiler configuration because it didn't look like it was provided by default to all JAX-RS deployments.

                           

                          I also removed the jboss-javaee-6.0-* pom imports and replaced the ee7 one with wildfly-javaee7-with-tools which should bring in Hibernate. I can't guarantee this will work, but it should be close Basically any dependency provided by the container should be marked as <scope>provided</scope>.

                           

                          With regards to the wildfly-maven-plugin all that does, the deploy case, is deploy the archive created by maven itself. In this case by the maven-war-plugin.

                           

                          <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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
                              <modelVersion>4.0.0</modelVersion>
                              <groupId>com.meritagesystems.codecompliance.rws</groupId>
                              <artifactId>CodeComplianceServices</artifactId>
                              <version>0.0.1-SNAPSHOT</version>
                              <packaging>war</packaging>
                              <name>CodeComplianceServices</name>
                              <url>http://maven.apache.org</url>
                              <properties>
                                  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
                                  <!-- BEGIN Careful not to break this version dependency -->
                                  <powermock.version>1.6.4</powermock.version>
                                  <mockito.version>1.10.19</mockito.version>
                                  <!-- END Careful not to break this version dependency -->
                                  <jackson.version>2.7.4</jackson.version>
                                  <hibernate.version>4.3.11.Final</hibernate.version>
                                  <jboss.bom.version>1.0.0.Final</jboss.bom.version>
                                  <wildfly.version>10.0.0.Final</wildfly.version>
                              </properties>
                              <dependencyManagement>
                                  <dependencies>
                                      <dependency>
                                          <groupId>org.wildfly.bom</groupId>
                                          <artifactId>wildfly-javaee7-with-tools</artifactId>
                                          <scope>import</scope>
                                          <type>pom</type>
                                          <version>${wildfly.version}</version>
                                      </dependency>
                                  </dependencies>
                              </dependencyManagement>
                              <dependencies>
                                  <dependency>
                                      <groupId>com.fasterxml.jackson.datatype</groupId>
                                      <artifactId>jackson-datatype-jsr310</artifactId>
                                      <version>${jackson.version}</version>
                                      <scope>provided</scope>
                                  </dependency>
                                  <dependency>
                                      <groupId>com.fasterxml.jackson.core</groupId>
                                      <artifactId>jackson-annotations</artifactId>
                                      <version>${jackson.version}</version>
                                      <scope>provided</scope>
                                  </dependency>
                                  <dependency>
                                      <groupId>org.hibernate</groupId>
                                      <artifactId>hibernate-core</artifactId>
                                      <version>${hibernate.version}</version>
                                      <scope>provided</scope>
                                  </dependency>
                                  <dependency>
                                      <groupId>org.hibernate</groupId>
                                      <artifactId>hibernate-validator</artifactId>
                                      <version>5.2.3.Final</version>
                                      <scope>provided</scope>
                                  </dependency>
                                  <dependency>
                                      <groupId>mysql</groupId>
                                      <artifactId>mysql-connector-java</artifactId>
                                      <version>5.1.38</version>
                                  </dependency>
                                  <dependency>
                                      <groupId>commons-beanutils</groupId>
                                      <artifactId>commons-beanutils</artifactId>
                                      <version>1.9.2</version>
                                  </dependency>
                                  <dependency>
                                      <groupId>org.apache.commons</groupId>
                                      <artifactId>commons-lang3</artifactId>
                                      <version>3.4</version>
                                  </dependency>
                          
                          
                                  <!-- Test Dependencies -->
                                  <dependency>
                                      <groupId>junit</groupId>
                                      <artifactId>junit</artifactId>
                                      <version>4.12</version>
                                      <scope>test</scope>
                                  </dependency>
                                  <dependency>
                                      <groupId>org.powermock</groupId>
                                      <artifactId>powermock-api-mockito</artifactId>
                                      <version>${powermock.version}</version>
                                      <scope>test</scope>
                                  </dependency>
                                  <dependency>
                                      <groupId>org.powermock</groupId>
                                      <artifactId>powermock-module-junit4</artifactId>
                                      <version>${powermock.version}</version>
                                      <scope>test</scope>
                                  </dependency>
                                  <dependency>
                                      <groupId>org.mockito</groupId>
                                      <artifactId>mockito-all</artifactId>
                                      <version>${mockito.version}</version>
                                      <scope>test</scope>
                                  </dependency>
                              </dependencies>
                              <build>
                                  <plugins>
                                      <plugin>
                                          <groupId>org.apache.maven.plugins</groupId>
                                          <artifactId>maven-compiler-plugin</artifactId>
                                          <version>3.5.1</version>
                                          <configuration>
                                              <source>1.8</source>
                                              <target>1.8</target>
                                              <encoding>UTF-8</encoding>
                                          </configuration>
                                      </plugin>
                                      <plugin>
                                          <!--
                                          The Maven Surefire plugin tests your application.
                                          Here we ensure we are using a version compatible with
                                          Arquillian
                                      -->
                                          <artifactId>maven-surefire-plugin</artifactId>
                                          <version>2.17</version>
                                      </plugin>
                                      <!-- The WildFly Maven Plugin deploys your war to a local WildFly container -->
                                      <!-- To use, set the JBOSS_HOME environment variable and run:
                                  mvn package wildfly:deploy -->
                                      <plugin>
                                          <groupId>org.wildfly.plugins</groupId>
                                          <artifactId>wildfly-maven-plugin</artifactId>
                                          <version>1.0.2.Final</version>
                                      </plugin>
                                      <plugin>
                                          <groupId>org.apache.maven.plugins</groupId>
                                          <artifactId>maven-war-plugin</artifactId>
                                          <version>2.6</version>
                                          <configuration>
                                              <failOnMissingWebXml>false</failOnMissingWebXml>
                                              <!-- Add module dependencies not automatically added by the container -->
                                              <archive>
                                                  <manifestEntries>
                                                      <Dependencies>com.fasterxml.jackson.datatype.jackson-datatype-jsr310</Dependencies>
                                                  </manifestEntries>
                                              </archive>
                                          </configuration>
                                      </plugin>
                                  </plugins>
                              </build>
                              <repositories>
                                  <repository>
                                      <id>my-repo1</id>
                                      <name>my custom repo</name>
                                      <url>http://mvnrepository.com/</url>
                                  </repository>
                              </repositories>
                          </project>
                          

                           

                           

                          Hope this helps,

                          James R. Perkins

                          • 11. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                            Bar Mid Newbie

                            This fixed the issue I was having. Thanks for taking the time to fix my POM, James.  That saved me a lot of time.

                             

                            Caveat: I now have a problem with Jackson JSR310 dependency: Caused by: org.jboss.modules.ModuleNotFoundException: com.fasterxml.jackson.datatype.jackson-datatype-jsr310:main

                            But that's a different issue. This may be the solution but it hasn't worked for me: java - How do I get Wildfly to use additional Jackson Datatypes? - Stack Overflow

                            • 12. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                              James Perkins Master

                              Ah yes. It doesn't look like that module is in WildFly 10.0.0.Final. It is available upstream which is where I was looking wildfly/module.xml at master · wildfly/wildfly · GitHub.

                               

                              If you download it you could install it as a module easily enough too. With CLI you can use the following command. Just replace the resource with the path to your downloaded JAR. It looks like 2.5.4 is the version of Jackson used in WildFly 10.0.0.Final

                              module add --name=com.fasterxml.jackson.datatype.jackson-datatype-jsr310 --resources=~/tmp/jackson-datatype-jsr310-2.5.4.jar --dependencies=com.fasterxml.jackson.core.jackson-core,com.fasterxml.jackson.core.jackson-databind,javax.api
                              

                               

                              --

                              James R. Perkins

                              • 13. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                                Bar Mid Newbie

                                This is one seriously twitchy class loader.

                                 

                                Just to try something to resolve the JSR310 issue, I commented out this part of the POM:

                                                    <!-- Add module dependencies not automatically added by the container

                                                    <archive> 

                                                        <manifestEntries> 

                                                            <Dependencies>com.fasterxml.jackson.datatype.jackson-datatype-jsr310</Dependencies> 

                                                        </manifestEntries> 

                                                    </archive>   --> 

                                 

                                and BOOM - right back to the original error: 19:54:48,147 INFO  [org.jboss.weld.Bootstrap] (Weld Thread Pool -- 1) WELD-000119: Not generating any bean definitions from com.meritagesystems.codecompliance.businessmodel.Inspection because of underlying class loading error: Type org.apache.commons.lang3.builder.ToStringStyle from [Module "deployment.CodeComplianceServices.war:main" from Service Module Loader] not found.

                                 

                                I had a successful deployment to WildFly but I was getting 404 response from the RWS call I was making to test it. I added a web.xml, although I thought this was unnecessary with JEE 7, with this stanza in it:

                                    <servlet-mapping>

                                        <servlet-name>javax.ws.rs.core.Application</servlet-name>

                                        <url-pattern>/*</url-pattern>

                                    </servlet-mapping>

                                 

                                and BOOM - right back to the original error: Type org.apache.commons.lang3.builder.ToStringStyle from [Module "deployment.CodeComplianceServices.war:main" from Service Module Loader] not found.


                                Reverting the POM and removing the web.xml gets me back to the JSR310 module issue.


                                This seems like a really straightforward, common stack - RESTEasy/Jackson/Hibernate - nothing exotic. Why is this so difficult? I don't get it.


                                • 14. Re: WildFly 10.0 - NoClassDefFoundError on deploy for classes defined in pom
                                  Bar Mid Newbie

                                  Ah - so if I define something in my POM that isn't "provided", I need to create a module for it?

                                   

                                  And, if that's true, then I probably shouldn't bother defining it in the POM? Or, does it have to be in both places?

                                  1 2 3 Previous Next