I have developed a custom mule library to verify and generate jwt token using java module. I imported my library in Mule application and added it to shared library. The custom library uses com.auth0.jwt package. I added it to mule-artifact.json in exportedPackages but still got error NoClassDefFoundError.
Error:
"Invocation of static Method 'main(java.lang.String[])' from Class 'com.mypackage.oauth.CustomAuth' with arguments [java.util.ArrayList<?> args] resulted in an error.\nExpected arguments are [java.lang.String[] args].\nCause: java.lang.NoClassDefFoundError - com/auth0/jwt/JWT"
mule-artifact.json in my custom library:
{
"minMuleVersion": "4.4.0",
"classLoaderModelLoaderDescriptor": {
"id": "mule",
"attributes": {
"exportedPackages": [
"com.mypackage.oauth"
]
}
}
}
Custom library java class is using these import statements:
package com.mypackage.oauth;
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;
And I added it to my mule application in shared library of mule-plugin:
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<classifier>mule-application</classifier>
<sharedLibraries>
<sharedLibrary>
<groupId>com.mypackage</groupId>
<artifactId>bi-auth-utils</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>
And as a dependency:
<dependency>
<groupId>com.mypackage</groupId>
<artifactId>bi-auth-utils</artifactId>
<version>1.0.9</version>
<classifier>mule-plugin</classifier>
</dependency>
I have already added jwt dependency in library pom.xml and imported xml file in the mule application to import the flows of mule library.
thank you @Aled and @Jim for your comments.
I fixed the issue by adding jwt library to the configuration of sharedLibrary in the Mule application:
<plugin>
<groupId>org.mule.tools.maven</groupId>
<artifactId>mule-maven-plugin</artifactId>
<version>${mule.maven.plugin.version}</version>
<extensions>true</extensions>
<configuration>
<classifier>mule-application</classifier>
<sharedLibraries>
<sharedLibrary>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</sharedLibrary>
<sharedLibrary>
<groupId>com.mypackage</groupId>
<artifactId>bi-auth-utils</artifactId>
</sharedLibrary>
<sharedLibrary>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
</sharedLibrary>
</sharedLibraries>
</configuration>
</plugin>