Running an error after the project is packaged - java

The project runs normally in eclipse, but there is a problem when the project is packaged and runs in the terminal. How should this problem be solved?
D:>java -jar
optaplanner-examples-7.4.1.Final-jar-with-dependencies.jar
D:\roster_450.xml 100 Exception in thread "main"
java.lang.ExceptionInInitializerError
at org.kie.api.internal.utils.ServiceRegistry.getInstance(ServiceRegistry.java:27)
at org.kie.api.KieServices$Factory$LazyHolder.(KieServices.java:332)
at org.kie.api.KieServices$Factory.get(KieServices.java:339)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildDroolsScoreDirectorFactory(ScoreDirectorFactoryConfig.java:460)
at org.optaplanner.core.config.score.director.ScoreDirectorFactoryConfig.buildScoreDirectorFactory(ScoreDirectorFactoryConfig.java:331)
at org.optaplanner.core.config.solver.SolverConfig.buildSolver(SolverConfig.java:220)
at org.optaplanner.core.impl.solver.AbstractSolverFactory.buildSolver(AbstractSolverFactory.java:61)
at org.optaplanner.examples.common.app.CommonApp.createSolver(CommonApp.java:105)
at org.optaplanner.examples.nurserostering.app.NurseRosteringApp.createSolutionBusiness(NurseRosteringApp.java:94)
at org.optaplanner.examples.nurserostering.app.NurseRosteringApp.init(NurseRosteringApp.java:85)
at org.optaplanner.examples.nurserostering.app.NurseRosteringApp.main(NurseRosteringApp.java:77)
Caused by: java.lang.RuntimeException: Child services
[org.kie.api.internal.assembler.KieAssemblers] have no parent
at org.kie.api.internal.utils.ServiceDiscoveryImpl.buildMap(ServiceDiscoveryImpl.java:186)
at org.kie.api.internal.utils.ServiceDiscoveryImpl.getServices(ServiceDiscoveryImpl.java:97)
at org.kie.api.internal.utils.ServiceRegistryImpl.(ServiceRegistryImpl.java:36)
at org.kie.api.internal.utils.ServiceRegistryImpl$LazyHolder.(ServiceRegistryImpl.java:32)
... 11 more

Drools doesn't like uber-jarring because several jars have a META-INF directory with files with the same name. So last-one-wins.
Either don't use uber-jarring or doing use Drools score calculation.

Related

Setting up LibPostal (JPostal) on Windows in Java

I'm trying to setup libpostal/jpostal on my Windows 10 machine in a Java environment. I followed the Windows Installation Guide on GitHub.
I am able to see the libpostal folder installed under: C:\xxx\Program Files\libpostal\ with sub folders: .git, autom4te.cache, data, m4, resources etc.
However, when I run:
AddressExpander expander = AddressExpander.getInstance();
I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpostal_expander in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at com.mapzen.jpostal.AddressExpander.<clinit>(AddressExpander.java:7)
at jpostal.JPostal.execute(JPostal.java:24)
at global_projects.GlobalMain.main(GlobalMain.java:37)
I normally use Maven for my build. However, since there is currently no Maven repository for JPostal, I am using Gradle.
I followed the solution suggested on this GitHub thread by adding the following gradle.build file, however I still get the same error.
What am I doing wrong?

How do I avoid java.lang.reflect.InvocationTargetException when using Gatling Frontline with compiled code?

I'm using Gatling Frontline to run load tests written in scala with sbt as the build tool. The project compiles, builds, and runs successfully locally. However, when running on a Frontline host, the host fails to connect to the injector pool because the injector process has crashed with an Exception in thread "main" java.lang.reflect.InvocationTargetException. The stack trace indicates that this exception is caused by
java.lang.NoClassDefFoundError: com/google/protobuf/ByteString$Output
and
java.lang.ClassNotFoundException: com.google.protobuf.ByteString$Output.
This error has never occurred locally, during development, as this google package is not used by my project. Could this problem be fixed by changing any of the jvm options supplied by Frontline, or by adding certain system properties or build properties.

maven dependencies works during compile, but fails during runtime java.lang.NoClassDefFoundError & java.lang.ClassNotFoundException

When I run my program on my compiler it works fine, but when I create the jar file, the maven dependencies that I'm working with fails to be referenced correctly when I run my jar file. I can't figure out what is going on. Can anyone help? I provided screenshots:
<dependency>
<groupId>org.languagetool</groupId>
<artifactId>language-en</artifactId>
<version>4.4</version>
<!--<scope>provided</scope>-->
<!--<scope>system</scope>-->
<!--<systemPath>${basedir}\src\lib\language-all-4.4.jar</systemPath>-->
</dependency>
Error I'm getting during runtime:
$ java -jar Spellcheck-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/languagetool/Language
at Spellcheck.App.main(App.java:22)`Exception in thread "main"
Caused by: java.lang.ClassNotFoundException: org.languagetool.Language
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
Actual output with compiler:
/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java...
Potential error at line: "speling erroor everwhere."
Did you mean: [spelling, spewing, spieling]
Potential error at line: "speling erroor everwhere."
Did you mean: [error]
Potential error at line: "speling erroor everwhere."
Did you mean: [everywhere, ever where]
Process finished with exit code 0
You need add language-en-4.4.jar to your classpath
in the same folder where is your jar add a folder "lib" with your dependencies
if your MANIFEST file (Spellcheck-1.0-SNAPSHOT.jar/META-INF/MANIFEST.MF) not contains "Class-Path: lib/language-en-4.4.jar" add classpath as argument with your dependencies separated by ";" in linux or ":" in windows
java -cp "/lib/language-en-4.4.jar:/lib/other.jar" -jar Spellcheck-1.0-SNAPSHOT.jar
if your MANIFEST file contains the classpath only verify the existence of lib folder an run without cp argument
java -jar Spellcheck-1.0-SNAPSHOT.jar

Properly Linking Library

I am trying to run a jar file that is using pi4j.
sudo java -classpath /opt/pi4j/lib/pi4j-core.jar -jar Test.jar test.Main
Problem is I keep getting this error
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/io/gpio/GpioFactory
at test.Main.main(Main.java:11)
Caused by: java.lang.ClassNotFoundException: com.pi4j.io.gpio.GpioFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
I don't see why the link isn't being made properly.
I have never done it in command line. But this worked for me:
in IntelliJ, I added the pi4J jar files to my project as modules. I then made an artifact and got IntelliJ to create a jar file for me (with all the dependencies including pi4J). Then I transferred the jar file to the pi and it ran fine.

VisualVM is unable to profile a web application on Eclipse

I would like to profile my Spring Web Application that is running on Tomcat and Eclipse. I added VisualVM to the Eclipse and followed below steps to run the application for profiling.
Right click on the application name >
Run As >
Run Configuration >
Java Application >
'Selected Project' >
Set 'org.apache.catalina.starup.Boostrap' as a value for Main class,
also selected VisualVM as the Launcher > clicked on Run button.
The VisualVM starts but shows following message:
"Cannot open requested application"
Under local I can see VisualVM, Eclipse and Tomcat.
Following exception will be thrown and shown on console as well:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/juli/logging/LogFactory
at org.apache.catalina.startup.Bootstrap.<clinit>(Bootstrap.java:59)
Caused by: java.lang.ClassNotFoundException: org.apache.juli.logging.LogFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
I reckon the issue is because of wrong server selected. Maybe I should choose Tomcat but not sure how.
Probably an issue with an incomplete classpath when the VisualVM plugin launches Tomcat. You could try to correct the classpath of the start configuration which you created (e.g. try to add bin/tomcat-juli.jar from your tomcat installation) but I doubt this will work easily.
You can try the following:
start your Tomcat, e.g. from Eclipse
then manually start VisualVM: It is actually part of the JDK and located in <JDK dir>/bin/jvisualvm(.exe)
in the application list you should see the Tomcat process and then you can open it with a double click.
Try using Java Mission Control by running jmc. It is included in recent versions of the JDK.
See the getting started doc at http://docs.oracle.com/javacomponents/jmc-5-5/jmc-user-guide/index.html
Run your application, then open the jmc window and connect to the Tomcat process.
This is caused when a class file that your code depends on is not found at run time. This is purely an issue with the class path. Either the class is not exists in the class path or you have a different version of JAR file in the class path. The exception will go away if the class path is corrected.

Categories

Resources