Developer Jahia 7.3 Jahia 8 Legacy

How to embed a jar in a module?

Question

After updating a module Jahia not able to resolve the classpath at runtime,  

java.lang.NoClassDefFoundError: com/mycompany/ums/security/CanadaUserService

Cause

Jahia is not able to find the missing classes.

Solution

First, you need to upload the missing jar to the maven repository.

mvn install:install-file -Dfile=[yourjar.jar] -DgroupId=com.mycompagny -DartifactId=YourLib -Dversion=1.1.6 -Dpackaging=jar -DgeneratePom=true

Then add the following dependency in your pom.xml 

<dependency>
    <groupId>com.mycompany</groupId>
    <artifactId>YourLib</artifactId>
    <version>1.1.6</version>
    <scope>compile</scope>
</dependency>

This will add automatically your jar in your Jahia module when building.