ExceptionInInitializerError exception when executing the built executable jar - java

I have tried to recreate the cloud balancing problem on a simple Java Application command line app. I didn't use any dependency manager, I just imported all the libraries provided on the Optaplanner distribution that can be downloaded on the site.
On IDE, things are working just fine. Problems happen when I execute the built executable jar file, I always got this exception:
Exception in thread "main" java.lang.ExceptionInInitializerError
at org.drools.core.rule.constraint.MvelConstraint.jitEvaluator(MvelConstraint.java:304)
at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:271)
at org.drools.core.rule.constraint.MvelConstraint.isAllowedCachedLeft(MvelConstraint.java:237)
at org.drools.core.common.SingleBetaConstraints.isAllowedCachedLeft(SingleBetaConstraints.java:135)
at org.drools.core.phreak.PhreakAccumulateNode.evaluateResultConstraints(PhreakAccumulateNode.java:653)
at org.drools.core.phreak.PhreakAccumulateNode.doNode(PhreakAccumulateNode.java:106)
at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:581)
at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:552)
at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:379)
at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:339)
at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:175)
at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:133)
at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:213)
at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:88)
at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1101)
at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1048)
at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1040)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1337)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1328)
at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1312)
at org.optaplanner.core.impl.score.director.drools.DroolsScoreDirector.calculateScore(DroolsScoreDirector.java:102)
at org.optaplanner.core.impl.score.director.AbstractScoreDirector.doAndProcessMove(AbstractScoreDirector.java:189)
at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.doMove(LocalSearchDecider.java:132)
at org.optaplanner.core.impl.localsearch.decider.LocalSearchDecider.decideNextStep(LocalSearchDecider.java:116)
at org.optaplanner.core.impl.localsearch.DefaultLocalSearchPhase.solve(DefaultLocalSearchPhase.java:70)
at org.optaplanner.core.impl.solver.AbstractSolver.runPhases(AbstractSolver.java:98)
at org.optaplanner.core.impl.solver.DefaultSolver.solve(DefaultSolver.java:189)
at se.digitaltolk.sample.Main.main(Main.java:21)
Caused by: java.lang.NullPointerException
at org.drools.core.rule.constraint.MvelConstraint$ExecutorHolder.<clinit>(MvelConstraint.java:330)
However, this exception only happens when I'm using the Drools solver and not when I'm using the Java solver.

Related

running junit testcase application from command line causes initialization errors

I have a testing application running as expected when executed on Eclipse IDE.
We want to export it to a jar and execute it via command line.
After executing, and running the application with the following comand, i encounter an error
java -jar testclient.jar -info
Error: Unable to initialize main class testclient.Main
Caused by: java.lang.NoClassDefFoundError: org/junit/runners/model/InitializationError
( -info) is an argument for the main method in the class.
Manifest file is pointing to the correct class.
On research of this topic, i checked whether the required libraries are added to the path. They are correctly added.
Could anyone provide some guidance

JDBC and RMI classpath conflict in ubuntu

I am trying to program in java using both jdbc and rmi but i am not able to to run the program without exporting classpath for stub for e.g. if my stub is located "home/java" i need to export it using "export CLASSPATH="home/java" and if i don't export it is throwing following exception :
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: GImplement_Stub
Now the problem is when i am exporting the path for the stub may be mysql database path is getting overwritten and it is throwing :
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
though if i am not exporting any path other jdbc programs are working fine.
How can this be resolved?
You can have multiple entries in the CLASSPATH variable and the -cp command-line argument separated by the colon character :.
However I would strongly recommend maven for this job, as it makes building way, way easier than juggling classpaths by hand...

.jar throwing UnsatisfiedLinkError only outside of IDE

I am using Netbeans to create a java application. The program works fine when I hit run in Netbeans. The problem is when I build the app and run it from the dist folder it throws the UnsatisfiedLinkError. I know this is caused by the libraries.
The error message is:
"Exception in thread "main" java.lang.UnsatisfiedLinkError:
jssc.SerialNativeInterface.openPort(Ljava/lang/String;Z)J"
Thank you for your help.

Is oracle driver can be installed on eclipse-link? or in glass fish? or where and how?

I'm currently creating a batch using JPA, with hierarchy of Tasklet-> accessor-> service-> processor, and i'm using Glassfish for my database. But then when I run`
[ERROR] [com.acts.core.jpa.dao.base.DAOFactory] - Exception
encountered with message Exception [EclipseLink-4003] (Eclipse
Persistence Services - 2.5.2.v20140319-9ad6abd):
org.eclipse.persistence.exceptions.DatabaseException Exception
Description: Configuration error. Class
[oracle.jdbc.driver.OracleDriver] not found.. This means that the
default constructor for the class
com.aeon.pms.orm.dao.impl.ConstantDaoImpl cannot be invoked. Throwing
DAOExecution Exception...`
is encountered. Is it mainly configuration error like the logs said? Do I need oracle driver? and i want to learn how to install it?
I'm using eclipse-link and I'm not familiar with this as i'm more used to using Netbeans, that's why I'm not sure if i'm missing on configurations. I'm so in need of help.
Thank you.
For oracle.jdbc.driver.OracleDriver you need to add one jar file to your project library,for this go to your oracle installation dir and find for classes12.jar and add it to your project library(whatever is netbeans or eclipse).
Or if you are not using any IDE then copy that jar file and past to program dir(where your .class is stored) and then run following command in cmd or terminal for run program.
java -classpath classes12.jar;. yourprogramclassname

UnsatisfiedLinkError with OpenCV in Tomcat

First of all, I have a basic example of OpenCV running in a main method.
However, if I use OpenCV in a Spring Web Controller, an error is thrown.
I am getting an UnsatisfiedLinkError when running the following code inside a Tomcat Server, within STS (Spring Tool Suite), and have boiled the problem down to the following code:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
CascadeClassifier cascadeClassifier = new CascadeClassifier();
The run configurations of both the server and the "main" application contain the VM Arguments pointing to the OpenCV DLLs:
-Djava.library.path="C:\opencv\build\java\x64;C:\opencv\build\x64\vc10\bin"
For reference, I have also included the pertinent bits of the stacktrace below:
org.springframework.web.util.NestedServletException: Handler processing failed;
nested exception is
java.lang.UnsatisfiedLinkError: org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0()J
...
Caused by: java.lang.UnsatisfiedLinkError:
org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0()J
at org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0(Native Method)
at org.opencv.objdetect.CascadeClassifier.<init>(CascadeClassifier.java:38)
at com.immersion.test.controllers.SimpleController.createClassifier(SimpleController.java:19)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
Note: I have read in several StackOverflow threads that the main cause of the UnsatisfiedLinkError is the missing System.loadLibrary(Core.NATIVE_LIBRARY_NAME) call. This is clearly not the case here, since it is being called just above where the exception is thrown.
Same thing here.
I try what Dylan said, but did not work here.
But I added "C:\opencv\build\java\x64;C:\opencv\build\x64\vc10\bin" on my PATH variable. On my sys variables.
ps: I'm using windows.
It turns out that the default run configuration to start a Tomcat server within STS/Eclipse is essentially just a launcher for Tomcat.
This means that any VM Args that are added to the Tomcat 'run configuration' will not be transferred to the actual Tomcat instance.
On looking in tcruntime-instance.bat within the Tomcat directory (this is what ends up creating the tomcat java instance), we can see that simply by adding our intended VM Args to the JAVA_OPTS environment variable, the dlls will be available to Tomcat.
TL;DR:
So.. Simply add the the locations of the OpenCV binaries to your JAVA_OPTS environment variable:
-Djava.library.path="C:\opencv\build\java\x64;C:\opencv\build\x64\vc10\bin"
For more information on setting JAVA_OPTS for Tomcat, see this SO question.

Categories