I'm trying to import a common-math Java jar into my mule project and just do basic functionality check of the java jar.
As per this blog https://mulesy.com/external-jar-class-in-dataweave/ I have added pom dependency and external package in mule-artifact.json.
mule-artifact.json
{
"minMuleVersion": "4.4.0",
"classLoaderModelLoaderDescriptor": {
"id": "mule",
"attributes": {
"exportedPackages": [
"org.apache.commons.math3"
]
}
}
}
My pom dependency:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
And now I have my data weave code has below:
%dw 2.0
import * from java!org::apache::commons::math3::primes::Primes
output application/json
---
{
a: Primes::isPrime(13)
}
It should return me either true or false as per java class.
But I'm getting error saying Unable to resolve the reference of: Primes::isPrime
What is missing, should I add the whole java package of primes in src/main/java?
Let me know how can I import an external java jar and perform the operations in Mulesoft defined in that jar..
Note: I have also installed this jar in my m2 repo
You are using the package
primewhen the correct package for Apache Commons Math3 isprimes. The full package name isorg.apache.commons.math3.primes.I'm not sure it is really needed to declare the
exportedPackageskey in mule-artifact.json. In many cases is automatically configured at build. I would try to remove it. If it still needed use the full package.