I run into the following problem: Upon running of the GPIO-example for my device built-in in Pi4J, I get an JNI error, followed by a NoClassDefFoundError for the com/pi4j/io/gpio/GpioProvider.
After some searching (both here and other websites) I came to the conclusion that I was missing the pi4j-gpio-extension.jar. Turns out I have to include these specifically while compiling. I was using:
pi4j --compile Gpioblabla.java
which is a macro/shorthand/dont know for
+ javac -classpath '.:classes:*classes:/opt/pi4j/lib/*' -d . Gpioblabla.java
This successfully compiles.
After running the program I get the NoClassDefError.
So the question is, how to explicitly include certain .jar files in pi4j/javac compilation?
Found the error. You need to run it with the classpath as well. So run it like:
java -classpath '.:classes:*classes:/opt/pi4j/lib/*' Gpioblabla
Related
I've never had issues with compiling with javac and running with java before, but here we are.
The program, MainApp.java, depends on a jar file and a few other programs, so I ran the following (which ran without issue):
javac -cp gson.jar *.java
However, when it comes time to run it, I can't seem to get it to work. I've tried:
java -cp gson.jar MainApp.java
but it complains that it can't find the other java files.
I then tried listing the file it said it was missing:
java -cp gson.jar RepositoryData.java MainApp.java
but it gave the same error.
I then tried listing all the dependencies:
java -cp gson.jar Comment.java Issue.java Owner.java Repository.java RepositoryData.java MainApp.java
but it complains that it can't find a main function in the Comment.java file - this leads me to think I'm going about this the wrong way, and I probably shouldn't be directly referencing dependencies in the java call.
I also know that the program does work, as I've compiled it using an editor without issue, but I'm required to do this via the command line for a class.
How should I be properly calling it?
I have a Java Code where I am able to run it on Intellij using custom configuration. The configuration has following attributes :-
module : java 8 (Oracle OpenJDK 1.8.0_321)
classpath : -cp XYZ.main()
main : com.ABC.XYZ.ManageTraffic
CLI arguements : server XYZ.yml
But when I try to run the jar that was build using gradle from terminal , it gives me Error , could not find or load main class com.ABC.XYZ.ManageTraffic
So far I have tried the following things looking at other solutions at Stackoverflow , still getting the same error
java -jar ques.jar
java -jar ques.jar com.ABC.XYZ.ManageTraffic
java -cp /build/libs/ques.jar com.ABC.XYZ.ManageTraffic
Just to cross check , I unzipped the creataed jar and found that com.ABC.XYZ.ManageTraffic class file is available there , still getting error. What could be the issue?
Run it from the IDE, and while it is running, try to get the command used by the IDE from the process list.
not sure what OS you are using but something like this should work on linux/mac:
ps -ef | grep java
After you have the command you can try to understand why its not working for you, or just use that command
Just want to add how I managed to run it. I created a new shaded jar file of the same application. refreshed its dependencies and now it works. I am yet to find out how creating a shaded jar instead of normal jar helped. Right now the only reason I could figure out is there may be version clashes with some dependencies but I wonder how it could throw could not found main class error.
Anyways , then I ran the file with the following command from terminal:
java -jar ./build/libs/ques-shaded.jar server XYZ.yml
Quick note, I went through every single other question through here and nothing seems to work.
So, here is my issue. All I want to do is create a windows batch script that will be used to execute my selenium project on Jenkins. Sounds simple right ? Its probably is, but I am missing something...
Here is my project https://github.com/Daviditooe/Nomad
First command I tried:
javac src/nomad/execute/Execute.java
Execute.java:9: error: package nomad.sites does not exist import nomad.sites.MmaShare;
It also couldnt find any of the jars, so I add all of them
Then I tried:
javac -cp Jars\* src\nomad\execute\Execute.java
This fixed the jars issue but the package not found still exists
So then I tried compiling every single package at the same time
javac -cp Jars\* src\nomad\execute\*.java src\nomad\actions\*.java src\nomad\baseactions\*.java src\nomad\browsers\Chrome.java src\nomad\directory\*.java src\nomad\scripts\*.java src\nomad\sites\*.java src\nomad\urltools\*.java
So, now its not crashing, then I tried compiling...
java src\nomad\execute\Execute
And its giving me Could not find or load main class
So That last thing I tried was compile all of them at the same time.
java src\nomad\actions\MmaShareActions src\nomad\baseactions\BaseActions src\nomad\browsers\Chrome src\nomad\directory\Directory src\nomad\execute\Execute src\nomad\scripts\Vpn src\nomad\sites\MmaShare src\nomad\urltools\UrlTools
Still no luck... anything thoughts would be appreciated.
Again: You must go into the src folder before you execute javac and java!
I can compile and execute it on my Linux Laptop:
stefan#stefanpc:/hdd/stefan/Downloads/Nomad-master/src$ javac -cp '../Jars/*' nomad/execute/*.java nomad/actions/*.java nomad/baseactions/*.java nomad/browsers/Chrome.java nomad/directory/*.java nomad/scripts/*.java nomad/sites/*.java nomad/urltools/*.java
Note: nomad/baseactions/BaseActions.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
stefan#stefanpc:/hdd/stefan/Downloads/Nomad-master/src$ java -cp '../Jars/*:.' nomad.execute.Execute
Exception in thread "main" java.lang.IllegalStateException: The driver executable does not exist: /hdd/stefan/Downloads/Nomad-master/src/C:\Users\Davidito\Desktop\AutoLinks\Jars\chromedriver.exe
Of course my Linux machine does not have the chromedriver.exe installed.
Under Windows, you must use "\" instead of "/" and you must use ";" instead of ":". Note that you must add the current folder "." to the class path when you execute the program. Otherwise java would only search in the Jars folder.
I was able to compile and run my java code from CMD, however when I try to run the same commands in PS, I am getting error messages. I have read and been told that CMD commands will work in PS, but the CMD commands are not working in PS
Here is the line that I am using to execute my program:
java -classpath .;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP
I am running the command from the directory where my needed JAR files are located. The error message says...
The command stanford-corenlp-3.8.0-models.jar was not found, but does exist
in the current location. Windows PowerShell does not load commands from the
current If you trust this command, instead type: ".\stanford-corenlp-3.8.0-
models.jar".
Made the change and the code looks like this now.
java -classpath .\;stanford-corenlp-3.8.0.jar;stanford-corenlp-3.8.0-
javadoc.jar;stanford-corenlp-3.8.0-models.jar;stanford-corenlp-3.8.0-
models.jar Test.TestCoreNLP
Still getting the exact same error message. I have also tried going up a directory and no luck. I have looked all over StackOverflow and I have done my research.
Any help would be much appreciated.
Thanks.
Using .\ would work for one file, but since you have a number of files, you should reference the current directory in each one of those files.
java -classpath .\stanford-corenlp-3.8.0.jar;.\stanford-corenlp-3.8.0-javadoc.jar;.\stanford-corenlp-3.8.0-models.jar;.\stanford-corenlp-3.8.0-models.jar .\Test.TestCoreNLP
Java 6 also supports wildcards, as this answer indicates, so you might try simply this.
java -cp ".\*" .\Test.TestCoreNLP
I came here with similar trouble, and what I found is that when running like this:
java -cp .\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar com.ethoca.app.myapp
I would get help info. My discovery is that I need to double-quote my list of classpath, like:
java -cp ".\target\somelib.jar;.\target\myapp-1.0-SNAPSHOT.jar" com.ethoca.app.myapp
I'm trying to send an email using JavaMail API.
I have jdk 1.5 installed in my home directory from self-extracting binary. I'm on Ubintu 9.10
I compile the program using the next command:
~/jdk1.5.0_22/bin/javac -classpath ~/jdk1.5.0_22/jre/lib/javamail-1.4.3/mail.jar:~/jdk1.5.0_22/jre/lib/jaf-1.1.1/activation.jar hw.java
It compiles OK. As you can see I have specified the path to mail.jar and activation.jar
Now I try to run the app using the next command:
~/jdk1.5.0_22/bin/java -classpath ~/jdk1.5.0_22/jre/lib/jaf-1.1.1/activation.jar:~/jdk1.5.0_22/jre/lib/javamail-1.4.3/mail.jar:. HelloWorldApp
I get an exception java.lang.NoClassDefFoundError: javax/mail/Address
Why can it find classes when compiling and cannot do it when running?
How to correctly run my app?
Thanks in advance
That class should come from your mail.jar. I'm not sure your classpath is being parsed properly. The tilde (~) is a shell function and needs expanding before being sent to the Java process. Have you tried removing the ~ and replacing with /home/{whatever} ? I suspect that's the issue.