java -jar and java.lang.NoClassDefFoundError - java

root#raspberrypi:/home/pi/java/src/driver# make run
java -jar Core.jar
Exception in thread "main" java.lang.NoClassDefFoundError: com/pi4j/io/gpio/GpioFactory
I used and altered a makefile that I'm sure of is correct, but let me include it as well:
http://pastebin.com/nzenp2E8
What do I do wrong?
Edit:
I know the imports are correct
And I've already tried like giving java -jar Core.jar a classpath in several ways, but the same error keeps popping up.

Create jar with -e option [specify application entry point for stand-alone application bundled into an executable jar file]:
jar cfe Core.jar pract2.Solution pract2\*
Here pract2.Solution is main class.
Run using
java -jar Core.jar
Or
java -cp .;Core.jar -jar Core.jar

Related

Running java -cp command for a maven project in intellij IDE

I have a maven project in intellij on windows.
Inside, I have a package with a file inside it:
build generates a jar named as 'outputjar':
I want to run java -cp command for the class, and tried various ways:
java -cp \target\outputjar\java\main\ jvm.LongRunningAlloc &
java -cp \target\outputjar jvm.LongRunningAlloc &
java -cp absolute-path-to-jar jvm.LongRunningAlloc &
But none works.
I always get:
Error: Could not find or load main class jvm.LongRunningAlloc
What is correct way of doing it?

Run a executable JAR file from the command line with Classpath

I have a Spring boot jar which I can run using the below command.
java -jar sample.jar
--spring.config.additional-location=application.properties
But, When I run the same jar with -cp, getting unable to find Main class error.
java -cp /usr/test/libs/* com.test.Sample
--spring.config.additional-location=application.properties
Not sure why it is not able to load the main class with this way?

How to include a jar file in classpath and run another jar in linux

I am trying to run a jar file on Linux but it requires another jar file to run. To be specific I have added ojdbc8 separately in Eclipse as I am unable to add it in pom.xml. In Eclipse it works fine but in Linux when I try to run the command
java -cp "/home/eim_master/EirRefresh/lib/ojdbc8.jar" -jar EirRefresh-0.0.1-SNAPSHOT.jar
even after including ojdbc8 jar it still fails throwing
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.OracleDriver
I need to run the main class and start the spring boot application
The -cp option is for a directory.
Try java -cp "/home/eim_master/EirRefresh/lib/" -jar EirRefresh-0.0.1-SNAPSHOT.jar
I tried this and it worked for me
java -cp "target/EirRefresh-0.0.1-SNAPSHOT.jar:lib/ojdbc8.jar" org.springframework.boot.loader.JarLauncher

Run main of specific class inside a package subdirectory

I am following Scheduled Jobs with Custom Clock Processes in Java with Quartz and RabbitMQ but I struggle to actually run another dyno from withing the jar file packeg by Spring.
In the package (server-1.0-SNAPSHOT.jar) I need to run the company.server.Scheduler. The .class file is in BOOT-INF/classes.
I've tried to do this but I am always getting
Error: Could not find or load main class company.server.Scheduler
I'm struggling to get the syntax right.
So what I need to run is
BOOT-INF/classes/company/server/Scheduler.class
I have tried this:
java -classpath BOOT-INF/classes -jar server-1.0-SNAPSHOT.jar company.server.Scheduler
java -classpath server-1.0-SNAPSHOT.jar:/BOOT-INF/classes company.server.Scheduler
But this either runs the main class from the Manifest or crashes.
Also tried:
java -classpath server-1.0-SNAPSHOT.jar BOOT-INF.classes.company.server.Scheduler
java -classpath server-1.0-SNAPSHOT.jar BOOT-INF/classes/company/server/Scheduler
Try it out ...
git clone https://github.com/silentsnooc/run-scheduler
cd run-scheduler/
mvn clean install
cd target/
java -cp .:scheduler-test-1.0-SNAPSHOT.jar BOOT-INF.classes.Scheduler
If I follow this on Heroku then it should be something like
java -cp scheduler-test-1.0-SNAPSHOT.jar:BOOT-INF/classes/* Scheduler
but it's not working telling me the main class Scheduler could not be found.

Including libraries generating jar and executing with java -jar on Intellij

I've been trying to execute a jar file through command line but I'm still getting an exception that I'm missing a library even though it was properly added as it's shown here. The library that I'm trying to run my code with is the opencv's lib. I'm able to run my app from intellij and generate a jar artifact that I can see the jar grows in size when I add the opencv lib but when I try to run the app from the command line with "java -jar Test.jar" I get the message that I'm missing the opencv library.
rinaldi#rinaldi-work:~/Projects/Test/out/artifacts/Test_jar$ java -jar Test.jar Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java310 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 HelloWorld.<clinit>(HelloWorld.java:14)
at Main.main(Main.java:4)
I've also tried to run the app adding the path to the opencv's library:
:~/Projects/Test/out/production/Test$ java -cp .:~/Sources/opencv-master/build/bin/opencv-310.jar Main
And another attempt because opencv needs not only it's jar but also the /opencv-master/build/lib/ directory:
:~/Projects/Test/src$ java -cp :/home/rinaldi/Sources/opencv-master/build/bin/opencv-310.jar:/home/rinaldi/Sources/opencv-master/build/lib/ Main
Below are the images from intellij's configuration.
I had to add the library this way:
java -jar -Djava.library.path=/home/rinaldi/Sources/opencv-master/build/lib test.jar
Hope this helps someone.

Categories

Resources