Question

I have a web application that depends on another maven project that has some provided dependencies in its pom file.

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-mapper-asl</artifactId>
    <version>1.9.12</version>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.codehaus.jackson</groupId>
    <artifactId>jackson-jaxrs</artifactId>
    <version>1.9.12</version>
    <scope>provided</scope>
</dependency>

When I deploy my war to JBoss, I get ClassNotFoundExceptions for JsonSerializer and Deserializer which are in the jackson-mapper-asl jar.

Caused by: java.lang.ClassNotFoundException: org.codehaus.jackson.map.JsonDeserializer from [Module "deployment.biz.modit.tit.gop.education.teacherportlets.createtest-0.0.1-SNAPSHOT.war:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]
... 26 more

If I'm not mistaken provided means that the runtime or in my case application server will provide the jar. The jackson-mapper-asl jar is installed on the JBoss server as a module. I thought the problem was caused by mismatching version numbers but updating the jars in the jboss modules and updating the module.xml-s didn't help. I tried deploying it copying it into the deployments folder because it helped before with the ojdbc driver but that didn't help either. Could you suggest something?

Was it helpful?

Solution

Change <scope>provided</scope> to <scope>compile</scope>.

Compile -This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

Provided - This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example, when building a web application for the Java Enterprise Edition, you would set the dependency on the Servlet API and related Java EE APIs to scope provided because the web container provides those classes. This scope is only available on the compilation and test classpath, and is not transitive.

Refer http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

OTHER TIPS

Since the server already has the dependencies provided you just need to make sure your deployment has a dependency on the modules. You can get more details about how to add module dependencies do your deployment in the documentation.

For a WAR just add something like the following to your pom.

<build>
   ...
   <plugins>
     <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-war-plugin</artifactId>
       <configuration>
          <archive>
             <manifestEntries>
                <Dependencies>org.codehaus.jackson.jackson-jaxrs,org.codehaus.jackson.jackson-mapper-asl</Dependencies>
             </manifestEntries>
          </archive>
       </configuration>
     </plugin>
   </plugins>
</build>

You can add the module containing required dependency to META-INF/jboss-deployment-structure.xml of the WAR (see 'JBoss Deployment Structure File' section here)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top