Reputation: 15094
I am getting NoClassDefFoundError when running my code in QA server, but localy (using Eclipse) it runs just fine.
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/csv/CSVFormat
I have faced this issue in another project which I fixed using the <wls:prefer-application-packages>
property. I checked the EAR file and the Apache CSV .jar is present in the build, and I did set the prefered application packages properly as well.
Here is my weblogic-application.xml
. Only org.apache.*
should be enough but it was not working so I added the complete Apache CSV package.
<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-application
xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-application"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/javaee_5.xsd http://xmlns.oracle.com/weblogic/weblogic-application http://xmlns.oracle.com/weblogic/weblogic-application/1.0/weblogic-application.xsd">
<wls:prefer-application-packages>
<wls:package-name>org.apache.*</wls:package-name>
<wls:package-name>org.apache.commons.*</wls:package-name>
<wls:package-name>org.apache.commons.csv.*</wls:package-name>
</wls:prefer-application-packages>
<wls:prefer-application-resources>
<wls:resource-name>org.apache.*</wls:resource-name>
</wls:prefer-application-resources>
</wls:weblogic-application>
My EAR POM declares the compile dependency:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.4</version>
</dependency>
And the EJB module POM uses it as provided:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.4</version>
<scope>provided</scope>
</dependency>
To be sure I checked the EAR build file generated by Maven, which we deploy into QA, and the Apache CSV jar is bundled inside de EAR file:
And the weblogic-application.xml file is also present under META-INF folder in the EAR file:
Even so I am getting NoClassDefFoundError
. Any ideas?
Upvotes: 0
Views: 960
Reputation: 15094
Add the <defaultLibBundleDir>lib</defaultLibBundleDir>
that tells Maven to create the application.xml
properly.
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.10.1</version>
<configuration>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<version>5</version>
</configuration>
</plugin>
And the application.xml
is created with that information:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
<!-- modules -->
<library-directory>lib</library-directory>
</application>
Upvotes: 1