Do I need to do something special to run a Service implemented in Java?
I’m getting ClassNotFoundException when I try to run my service. Interestingly I cannot find any example of a working Java service.
As reference, the component repo is on github at: grozadanut/moqui-linic-legacy/
Caused by: java.lang.ClassNotFoundException: Class not found.
at org.moqui.util.MClassLoader.loadClassInternal(MClassLoader.java:433)
at org.moqui.util.MClassLoader.loadClass(MClassLoader.java:381)
at org.moqui.util.MClassLoader.loadClass(MClassLoader.java:370)
at org.moqui.impl.service.runner.JavaServiceRunner.runService(JavaServiceRunner.groovy:62)
This is my service definition:
<services xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://moqui.org/xsd/service-definition-3.xsd">
<!-- moqui-linic-legacy & Related Services -->
<service verb="legacySync" noun="AllProducts" type="java"
location="ro.colibri.legacy.service.LegacySyncServices" method="syncAllProducts">
<description>
Synchronizes all ACTIVE products(no images) from the legacy database to the Moqui database. No stock, just initial data.
</description>
</service>
</services>
1 Like
Okay, got it to work. So it seems I misunderstood what the lib folder was for. I was expecting that the lib folder is to add jar dependencies that my code needs, but it seems it is only for jars that Moqui framework needs to discover, thus I need to build the jar of my code and add it there in order for Moqui to see my code.
So I ended up creating another libs folder where I put the jars that are dependencies of my code, and the gradle build task makes sure that all those jars, and also my library jar gets copied to the lib folder.
@newmannhu yea, probably Groovy is more convenient, but I have little experience with it, and I needed to call a legacy system through remote ejb calls, for which I already had the code written, just needed to copy it to Moqui.
1 Like
In a component you can define your dependencies in the build.gradle
file like: moqui-sftp/build.gradle at 6747a3ea2f37580f5e0fe2c47b2ae2628b62396d · moqui/moqui-sftp · GitHub
You can also add dependencies for your component in the lib folder as long as the build.gradle file knows where to get it: moqui-sftp/build.gradle at 6747a3ea2f37580f5e0fe2c47b2ae2628b62396d · moqui/moqui-sftp · GitHub
If you have external code you need to call that you’ve already written, you can build the jar, import as a dependency through gradle, or just copy the code to component/src/java
like: mantle-braintree/src at 39a1c9a84b4fd2e6425e2d25884e336a5408aa0d · moqui/mantle-braintree · GitHub
1 Like
Yes, the dependencies in build.gradle
work fine, but I need these specific legacy jars that don’t have Maven repositories. Simply copying them to the lib folder doesn’t work because the lib folder is deleted and recreated when copyDependencies is run. See cleanLib:
copyDependencies.dependsOn cleanLib
jar.dependsOn copyDependencies
What seemed to work for me is to put them in another libs folder and add them to the dependencies in build.gradle and they automatically get copied to the lib folder when building. I would leave a link to my build.gradle, but it seems I cannot add links. Anyway, this is the code in the build that works for me:
dependencies {
implementation project(':framework')
testImplementation project(':framework').configurations.testImplementation.allDependencies
// Add moqui-linic-legacy dependencies here
implementation fileTree('/libs')
}