Exception in ChronicleHashRecoveryFailedException: java.lang.UnsatisfiedLinkError: Can't find dependent libraries - java

I get the following error when I try to create a ChronicleMap:
Exception in thread "main" net.openhft.chronicle.hash.ChronicleHashRecoveryFailedException: java.lang.UnsatisfiedLinkError: C:\Users\sando\AppData\Local\Temp\jna-109203563\jna13551597900255569913.dll: Can't find dependent libraries
at net.openhft.chronicle.map.ChronicleMapBuilder.openWithExistingFile(ChronicleMapBuilder.java:1877)
at net.openhft.chronicle.map.ChronicleMapBuilder.createWithFile(ChronicleMapBuilder.java:1701)
at net.openhft.chronicle.map.ChronicleMapBuilder.recoverPersistedTo(ChronicleMapBuilder.java:1655)
at net.openhft.chronicle.map.ChronicleMapBuilder.createOrRecoverPersistedTo(ChronicleMapBuilder.java:1638)
at net.openhft.chronicle.map.ChronicleMapBuilder.createOrRecoverPersistedTo(ChronicleMapBuilder.java:1629)
at com.mycompany.app.App.createIndexOneFile(App.java:54)
at com.mycompany.app.App.createIndexOne(App.java:31)
at com.mycompany.app.App.main(App.java:23)
Caused by: java.lang.UnsatisfiedLinkError: C:\Users\sando\AppData\Local\Temp\jna-109203563\jna13551597900255569913.dll: Can't find dependent libraries
at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2430)
at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2487)
at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2684)
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2617)
at java.base/java.lang.Runtime.load0(Runtime.java:765)
at java.base/java.lang.System.load(System.java:1834)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:851)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:826)
at com.sun.jna.Native.<clinit>(Native.java:140)
at net.openhft.chronicle.hash.impl.util.jna.WindowsMsync.<clinit>(WindowsMsync.java:34)
at net.openhft.chronicle.hash.impl.VanillaChronicleHash.msync(VanillaChronicleHash.java:853)
at net.openhft.chronicle.hash.impl.VanillaChronicleHash.msync(VanillaChronicleHash.java:841)
at net.openhft.chronicle.map.ChronicleMapBuilder.commitChronicleMapReady(ChronicleMapBuilder.java:464)
at net.openhft.chronicle.map.ChronicleMapBuilder.openWithExistingFile(ChronicleMapBuilder.java:1871)
... 7 more
Using this code:
String indexOnePath = "D:\\trabajo\\dbpedia\\dbpedia_files\\indexOne.bin";
File indexOneFile = new File(indexOnePath);
indexOne = ChronicleMap
.of(String.class, String.class)
.name("indexOne")
.entries(27191196)
.averageValue("<http://dbpedia.org/resource/Robert_Koch>")
.averageKey("Battle of Ardrianople")
.createOrRecoverPersistedTo(indexOneFile, true);
My pom.xml dependency looks like this:
<dependency>
<groupId>net.openhft</groupId>
<artifactId>chronicle-map</artifactId>
<version>3.19.4</version>
</dependency>
I am using the Java SDK 11.0.6 on Windows 10.
It seems to create the file, but then the exception appears. If I use create insteaad of createOrRecoverPersistedTo, there seems to be no problem.

Latest released version of Chronicle-Map depends on fairly old jna version (4.2.1) which doesn't work well with recent Windows. You can try last snapshot version (3.19.5-SNAPSHOT) as we haven't released it yet, or try overriding jna version in maven, e.g. add this to your dependency-management section:
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.5.0</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>5.5.0</version>
</dependency>

Related

NoClassDefFoundError while deploying a OpenID Azure AD java web-app on Weblogic

I am trying to integrate Azure AD for my web-app using OpenIDConnect approach. When I try to deploy the built ear file on weblogic I get NoClassDefFound for
com.nimbusds.openid.connect.sdk.AuthenticationSuccessResponse
. I have included oauth2-oidc-sdk-5.24.1.jar in the web-inf/lib folder, also verified that it is actually present within the ear file yet the application deployment fails complaining it is not able to find this class.
I found similar issue here. So I tried deploying both oauth2-oidc-sdk-5.24.1.jar and gson jar file as a library along with my java web app, but that did not help as well.
Much appreciated if I can get any pointers or suggestions to overcome this error.
The full stacktrace during deployment:
Caused By: java.lang.NoClassDefFoundError: com/nimbusds/openid/connect/sdk/AuthenticationSuccessResponse
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2436)
at java.lang.Class.getDeclaredMethods(Class.java:1793)
at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.getMethods(BaseJ2eeAnnotationProcessor.java:1055)
at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.getMethods(BaseJ2eeAnnotationProcessor.java:1043)
at weblogic.j2ee.dd.xml.BaseJ2eeAnnotationProcessor.processJ2eeAnnotations(BaseJ2eeAnnotationProcessor.java:99)
at weblogic.j2ee.dd.xml.J2eeAnnotationProcessor.processJ2eeAnnotations(J2eeAnnotationProcessor.java:37)
at weblogic.servlet.internal.WebAnnotationProcessorImpl.processFilters(WebAnnotationProcessorImpl.java:239)
at weblogic.servlet.internal.WebAnnotationProcessorImpl.processJ2eeAnnotations(WebAnnotationProcessorImpl.java:210)
at weblogic.servlet.internal.WebAnnotationProcessorImpl.processAnnotations(WebAnnotationProcessorImpl.java:105)
at weblogic.servlet.internal.WebAppServletContext.processAnnotations(WebAppServletContext.java:1370)
at weblogic.servlet.internal.WebAppServletContext.<init>(WebAppServletContext.java:450)
at weblogic.servlet.internal.WebAppServletContext.<init>(WebAppServletContext.java:494)
at weblogic.servlet.internal.HttpServer.loadWebApp(HttpServer.java:418)
at weblogic.servlet.internal.WebAppModule.registerWebApp(WebAppModule.java:976)
at weblogic.servlet.internal.WebAppModule.prepare(WebAppModule.java:384)
at weblogic.application.internal.flow.ScopedModuleDriver.prepare(ScopedModuleDriver.java:176)
at weblogic.application.internal.flow.ModuleListenerInvoker.prepare(ModuleListenerInvoker.java:199)
at weblogic.application.internal.flow.DeploymentCallbackFlow$1.next(DeploymentCallbackFlow.java:517)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:159)
at weblogic.application.internal.flow.DeploymentCallbackFlow.prepare(DeploymentCallbackFlow.java:45)
at weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:648)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:52)
at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:191)
at weblogic.application.internal.EarDeployment.prepare(EarDeployment.java:59)
at weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:154)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.createAndPrepareContainer(ActivateOperation.java:208)
at weblogic.deploy.internal.targetserver.operations.ActivateOperation.doPrepare(ActivateOperation.java:98)
at weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217)
at weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:747)
at weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1216)
at weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:250)
at weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159)
at weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:171)
#####################################
Update 2021/06/02
To resolve the version compatibility issue, I had to opt below specific versions of dependencies to get it not throw the error for JDK1.6, and microsoft adal4j had to recompiled in JDK6 (adal4j jar is supported on jdk1.7 and above)
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<classifier>jdk16</classifier>
<version>5.9</version>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<classifier>jdk16</classifier>
<version>5.24.1</version>
</dependency>
If the JDK is 1.7, below is the specific versions that worked for me:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>oauth2-oidc-sdk</artifactId>
<version>5.24.1</version>
</dependency>
<dependency>
<groupId>com.nimbusds</groupId>
<artifactId>nimbus-jose-jwt</artifactId>
<version>7.8</version>
</dependency>
Hope this helps someone facing similar error on JDK1.6 and JDK1.7
This is usually caused by incompatible versions. You can try different versions of oauth2-oidc-sdk until you find a compatible package.
Or you can also change the version of spring to achieve the purpose of version compatibility as mentioned in the comments.

Junit tests not working with Drools 5.4.0.Final and JDK 8

I recently started upgrading my application JDK version from jdk1.7.0_121_x64 to jdk1.8.0_202_x64. I have some legacy code using Drools 5.4.0.Final. This code is working with JDK version jdk1.7.0_121_x64 without any issue.
Maven dependencies are:
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>5.4.0.Final</version>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>5.4.0.Final</version>
</dependency>
DRL files are loaded as:
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(resource, ResourceType.DRL);
knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
I was aware that there are issues using Drools with JDK 8. I referrred to other SO thread to start with.
When I built my application and executed Junit tests using JDK 8, tests failed with error:
testRunRule(com.company.app.RuleTest) Time elapsed: 0.073 sec <<< ERROR!
java.lang.RuntimeException: java.lang.RuntimeException: wrong class format
at org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader.<init>(ClassFileReader.java:372)
at org.drools.commons.jci.compilers.EclipseJavaCompiler$2.createNameEnvironmentAnswer(EclipseJavaCompiler.java:287)
at org.drools.commons.jci.compilers.EclipseJavaCompiler$2.findType(EclipseJavaCompiler.java:258)
As mentioned in SO thread, I found reference to this bugfix ticket DROOLS-329.
Based on approaches mentioned in this bugfix ticket, I tried to use JANINO compiler:
Added following maven dependency:
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>2.5.16</version>
</dependency>
I added following VM argument (I was running tests from eclipse, so in eclipse launch configuration in JRE VM argument added the argument):
-Ddrools.dialect.java.compiler=JANINO
I could still see the wrong class format error. So I modified my code to load DRL files as:
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
final Properties props = new Properties();
props.setProperty("drools.dialect.java.compiler", "JANINO");
final KnowledgeBuilderConfiguration config = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(props, null);
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(config);
kbuilder.add(resource, ResourceType.DRL);
knowledgeBase.addKnowledgePackages(kbuilder.getKnowledgePackages());
It didn't help. I could still see the wrong class format error.
I followed another apprroach mentioned in this external link. I updated added/updated maven dependencies as:
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-core</artifactId>
<version>5.4.0.Final</version>
<exclusions>
<exclusion>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.drools</groupId>
<artifactId>drools-decisiontables</artifactId>
<version>5.4.0.Final</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
</exclusion>
<exclusion>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.mvel</groupId>
<artifactId>mvel2</artifactId>
<version>2.1.9.Final</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
</dependency>
mvel2 patch is built using:
https://github.com/mkornipati/mvel/tree/2.1.9.Final.Patch
With this wrong class format error is gone. But my tests are now failing with following error:
testRunRule(com.company.app.RuleTest)) Time elapsed: 4.684 sec <<< ERROR!
java.lang.RuntimeException: org.drools.rule.InvalidRulePackage: Rule Compilation error : [Rule name='ruleCheck']
org/drools/template/parser/Rule_ruleCheck_8eb4621227714a36b7b84c8b764527e4.java (2:80) : Only a type can be imported. java.util.Map resolves to a package
org/drools/template/parser/Rule_ruleCheck_8eb4621227714a36b7b84c8b764527e4.java (2:101) : Only a type can be imported. java.util.HashMap resolves to a package
org/drools/template/parser/Rule_ruleCheck_8eb4621227714a36b7b84c8b764527e4.java (6:299) : org.drools.spi.KnowledgeHelper cannot be resolved to a type
org/drools/template/parser/Rule_ruleCheck_8eb4621227714a36b7b84c8b764527e4.java (6:339) : org.drools.template.parser.Row cannot be resolved to a type
org/drools/template/parser/Rule_ruleCheck_8eb4621227714a36b7b84c8b764527e4.java (6:373) : org.drools.FactHandle cannot be resolved to a type
org/drools/template/parser/Rule_ruleCheck_8eb4621227714a36b7b84c8b764527e4.java (6:411) : org.drools.template.parser.DefaultGenerator cannot be resolved to a type
org/drools/template/parser/Rule_ruleCheck_8eb4621227714a36b7b84c8b764527e4.java (6:487) : org.drools.runtime.rule.RuleContext cannot be resolved to a type
at org.drools.rule.Package.checkValidity(Package.java:445)
I don't know how to proceed further. Please let me know if you are able to make Drools 5.4 work with JDK 8.
I used Drools 7.7.0 with Java 8 and worked great for me. I am not sure what is the oldest Drools version that is compatible with Java 8. That said, Drools 5.4.0 was released in 2011. Java 8 was released in 2014, so you can assume it won't be compatible. Java 7 was released in July 2011. Depending on when 5.4.0 was released it might or might not be. Based on that, I expect Drools 5.4.0 to be compatible with Java 6 or earlier. If you want to use Java 8 with Drools, I don't see how you can without upgrading. I think the earliest compatible version is 6.1.0 download.jboss.org/drools/release.
In summary: Either downgrade your project to Java 6 to use Drools 5.4.0 or Upgrade Drools to use 6.1.0. Better yet, upgrade to latest Drools and then figure out what is the latest Java version it supports.

java.lang.UnsatisfiedLinkError: Can't find dependent libraries only during debugging

I'm working on studens project, which will need to read data send from AtMega via USB (using virtual serial port). To access serial port I'm using NeuronRobotics' nrjavaserial (https://github.com/NeuronRobotics/nrjavaserial), which is a fork of RXTX. To manage my dependencies I'm using maven. Here's what I get when I run CommPortIdentifier.getPortIdentifiers(); (or whichever static CommPortIdentifier function):
java.lang.UnsatisfiedLinkError: C:\Users\Grześ\AppData\Local\Temp\libNRJavaSerial_Grze?_0\libNRJavaSerial.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at gnu.io.NativeResource.loadResource(NativeResource.java:142)
at gnu.io.NativeResource.inJarLoad(NativeResource.java:40)
at gnu.io.NativeResource.loadLib(NativeResource.java:60)
at gnu.io.NativeResource.load(NativeResource.java:28)
at gnu.io.SerialManager.<init>(SerialManager.java:10)
at gnu.io.SerialManager.getInstance(SerialManager.java:16)
at gnu.io.RXTXCommDriver.<clinit>(RXTXCommDriver.java:87)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:109)
at pl.edu.pwr.aerospace.enginebench.serial.SerialCommunicator.getAvaliablePorts(SerialCommunicator.java:34)
at pl.edu.pwr.aerospace.enginebench.cli.Main.connectCommunicator(Main.java:35)
at pl.edu.pwr.aerospace.enginebench.cli.Main.main(Main.java:21)
java.lang.UnsatisfiedLinkError: C:\Users\Grześ\AppData\Local\Temp\libNRJavaSerial_Grze?_0\libNRJavaSerial.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1938)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1821)
at java.lang.Runtime.load0(Runtime.java:809)
at java.lang.System.load(System.java:1086)
at gnu.io.NativeResource.loadResource(NativeResource.java:142)
at gnu.io.NativeResource.inJarLoad(NativeResource.java:40)
at gnu.io.NativeResource.loadLib(NativeResource.java:60)
at gnu.io.NativeResource.load(NativeResource.java:28)
at gnu.io.SerialManager.<init>(SerialManager.java:10)
at gnu.io.SerialManager.getInstance(SerialManager.java:16)
at gnu.io.RXTXCommDriver.<clinit>(RXTXCommDriver.java:87)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at gnu.io.CommPortIdentifier.<clinit>(CommPortIdentifier.java:109)
at pl.edu.pwr.aerospace.enginebench.serial.SerialCommunicator.getAvaliablePorts(SerialCommunicator.java:34)
at pl.edu.pwr.aerospace.enginebench.cli.Main.connectCommunicator(Main.java:35)
at pl.edu.pwr.aerospace.enginebench.cli.Main.main(Main.java:21)
java.lang.ExceptionInInitializerError thrown while loading gnu.io.RXTXCommDriver
java.lang.NoClassDefFoundError: Could not initialize class gnu.io.RXTXCommDriver thrown while loading gnu.io.RXTXCommDriver
Here are my dependencies:
<dependencies>
<dependency>
<groupId>com.neuronrobotics</groupId>
<artifactId>nrjavaserial</artifactId>
<version>3.12.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
Strangly, this only happens during debugging, when I run program normally it works like charm. Any ideas why?
I found that people had similar problems with other libraries, however solutions for all of them was to move DLLs or update classpath, but as I'm using maven I suspect in this case the solution will be different.
I managed to fix my problem. The root cause of this problem, was my username - "Grześ", which contains non-standard character 'ś'. As you may see in the first line of exception info:
java.lang.UnsatisfiedLinkError: C:\Users\Grześ\AppData\Local\Temp\libNRJavaSerial_Grze?_0\libNRJavaSerial.dll: Can't find dependent libraries
The path contains question mark in place of this character. Changing my username in Windows properties fixed this issue

java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil

I am using Windows10, eclipse-neon with JDK1.8 version,
I am getting the following exception.
Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.bytedeco.javacpp.Loader.load(Loader.java:385)
at org.bytedeco.javacpp.Loader.load(Loader.java:353)
at org.bytedeco.javacpp.avformat$AVFormatContext.<clinit>(avformat.java:2719)
at org.bytedeco.javacv.FFmpegFrameGrabber.startUnsafe(FFmpegFrameGrabber.java:391)
at org.bytedeco.javacv.FFmpegFrameGrabber.start(FFmpegFrameGrabber.java:385)
at com.segment.processor.AudioMain.main(ApacheMathAudioMain.java:20)
Error getting static method ID of org/bytedeco/javacpp/Loader/putMemberOffset
here are the dependencies I am using in my pom.xml
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg</artifactId>
<version>3.0.2-1.2</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv</artifactId>
<version>3.1.0-1.2</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>0.10</version>
</dependency>
First problem
Your versions don't match. org.bytedeco.javacpp in version 0.10 is from Dec 2014, while all your other versions are from May 2016. You need to use version 1.2 of org.bytedeco.javacpp, or better yet, update all dependencies to the latest version.
You can see the versions here:
org.bytedeco.javacpp-presets » opencv
org.bytedeco.javacpp-presets » ffmpeg
org.bytedeco » javacv
org.bytedeco » javacpp
Second problem
You include the dependencies for Java code only, but you don't include the dependencies for native code (both opencv and ffmpeg are native libraries). You need to include opencv-platform and ffmpeg-platform instead:
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacpp</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco</groupId>
<artifactId>javacv</artifactId>
<version>1.4.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>opencv-platform</artifactId>
<version>3.4.1-1.4.1</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>ffmpeg-platform</artifactId>
<version>3.4.2-1.4.1</version>
</dependency>
This will make Maven download and include opencv and ffmpeg libraries for Android, Linux, MacOS and Windows, both x86 and x64.
java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.avutil
Actual cause of error is different versions of dependencies. That's why javacpp package failed during mapping of classes.
Follow these step to resolve this problem:
Download latest version of Javacv library package from here
Copy these three .jar files into libs folder
ffmpeg.jar
javacv.jar
javacpp.jar
Create jniLibs folder in app\src\main
Now, create four different folders for different architectures
arm64-v8a
armeabi
armeabi-v7a
x86
Change extension of these two files ffmpeg-android-arm.jar, ffmpeg-android-x86.jar to .zip then unzip both folders and Copy .so files for each architecture and paste in its respected directory. Your resultant directory should be look like this
Add .jar dependencies in your gradle file as follows:
implementation files('libs/ffmpeg.jar')
implementation files('libs/javacpp.jar')
implementation files('libs/javacv.jar')```
Thanks for reading :)
Try to update the dependencies with the latest versions and check whether class exists in that or not
https://mvnrepository.com/artifact/org.bytedeco/javacv/1.4.1
https://mvnrepository.com/artifact/org.bytedeco.javacpp-presets/ffmpeg/3.4.2-1.4.1
https://mvnrepository.com/artifact/org.bytedeco.javacpp-presets/opencv/3.4.1-1.4.1
This means that the class is there at compiletime but missing at runtime. You have a couple of options:
Always execute with a Maven plugin.
Include the library in the classpath when running.
Use the Maven Shade plugin to make an Uber-Jar which includes dependencies.
I hope this helps!

Maven dependencies in a Mule project . Classloader control not working as expected

I'm trying to build a mule project in maven which uses a library that in turn uses apache-commons-codec-1.8 . Mule 3.5 currently supports only v 1.3
In order to get around this Ive implemented classloader control in mule and blocked mule from loading its version of the library by doing the following in mule-deploy.properties.
loader.override=-org.apache.commons.codec
In addition I've updated my pom.xml to include the 1.9 version of the library . Here is a snapshot of running mvn:dependency tree on the project.
However, when I run my test method I get a runtime exception
java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64URLSafeString([B)Ljava/lang/String;
at com.nimbusds.jose.util.Base64URL.encode(Base64URL.java:64)
at com.nimbusds.jose.util.Base64URL.encode(Base64URL.java:91)
at com.nimbusds.jose.Header.toBase64URL(Header.java:238)
at com.nimbusds.jose.JWSObject.<init>(JWSObject.java:101)
at com.package.components.lastmile.originator.TokenSignerTemplate.sign(TokenSignerTemplate.java:109)
at com.package.components.lastmile.originator.TokenSignerTemplate.signClaim(TokenSignerTemplate.java:122)
at com.package.orchestration.LMSFakeClaimsHandler.testSignParse_Positive(LMSFakeClaimsHandler.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
which is clearly because it's referencing the older version of apache-commons. How do I make sure that it references only the latest version and not the older version?
mule-deploy.properties
#Fri Dec 12 09:58:12 PST 2014
loader.override=-org.apache.commons.codec
redeployment.enabled=true
encoding=UTF-8
domain=default
config.resources=..flows.
.
Relevant positions of pom.xml
<dependencies>
....
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
....
<!-- Test to check commons-codec works -->
<dependency>
<groupId>org.mule.transports</groupId>
<artifactId>mule-transport-http</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
P.S: The same snippet seems to work fine on a non mule project, indicating this is a mule related issue.
If you are running the Mule app in Mule server, excluding the lib from the pom will not work, since the codec lib is present in the server itself.
Try to insert the newest codec lib version in the server lib shared folder (maintaining the property loader.override=-org.apache.commons.codec)
Add the following exclusion to your pom.
<dependency>
<groupId>org.mule.transports</groupId>
<artifactId>mule-transport-http</artifactId>
<version>${mule.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</exclusion>
</exclusions>
</dependency>
And then add the dependency of Commons Codec 1.9.
Then your override property in mule-deploy.properties will work as expected.
Update: 12/30:
The override property seems to be the problem.
loader.override=-org.apache.commons.codec is not correct.
Try the following
loader.override=org.apache.commons.codec
Hope this helps.
I have a similar issue with the jackson-xc. I don't know why Mule 3.5 comes with a mix of jackson 1 and 2 libraries
jackson-annotations-2.1.1.jar
jackson-core-2.1.1.jar
jackson-databind-2.1.1.jar
jackson-core-asl-1.9.11.jar
jackson-jaxrs-1.9.11.jar
jackson-mapper-asl-1.9.11.jar
jackson-xc-1.7.1.jar
And with jackson-xc-1.7.1 instead of jackson-xc-1.9.11 that would be aligned to the version of the other jackson 1 libraries.
In my application it is producing the "classic" library issue exception:
Caused by: java.lang.AbstractMethodError
at org.codehaus.jackson.map.AnnotationIntrospector$Pair.findDeserializer(AnnotationIntrospector.java:1335)
Since using
loader.override=...
into the mule-deploy.properties didn't work (with either override and/or blocking on the package org.codehaus.jackson.xc and on the class org.codehaus.jackson.xc.JaxbAnnotationIntrospector) the only solution I have found goes in the direction of Nuno's answer and is to put the jar we want to use in a lib folder with higher priority than lib/opt
lib/shared has been deprecated but you can use lib/user to override.
I would prefer to use the loader.override (classloader-control-in-mule 3.5) and avoid the modification of all the installation, but for now is the only solution that is working for me.

Categories