Set jna.library.path from Command line shows error - java

I am new to Java and JNA. I was trying to access the native interfaces of a third party applications using JNA from Java eclipse. So I was trying to set the jna.library.path from Command line using the command
java -Djna.library.path=<path to your library> MainClass
I have given the "path to your library" as the path of the folder where my .dll file and its dependencies are there. for ex: D:Adrin\Library\Dll.
"MainClass" I have given the name of the class with main() in my application(Jnaexe.java). But an error occurs saying
Error: Could not find or load main class Jnaexe.java
I have also tried by giving the package name and also the whole path of the Jnaexe.java. Still it does't work. I tried running from the src folder and even the folder where Jnaexe.java file is there(example folder) in command prompt. But the error was same.What I am missing here. Any help will be highly appreciated. Thank you in advance

Related

Executing java jar file gives error when passing user.dir in command line?

When I run the following everything works fine:
# WORKS CORRECTLY
java -jar target/example.jar
# GIVES AN ERROR
java -Duser.dir="/webapp" -jar target/example.jar
The error output is:
Error: Could not find or load main class com.module.Main
I'm using Java 7.
My Manifest file is configured correctly in the jar file to contain the "Main-Class: com.module.Main"
I can't find an explanation for why this takes place.
Make sure package name is correct on your class with main.
If your sourcesets are custom, IDE will amend your package with main.java. etc
Setting the user.dir changes your working directory, hence the location it tries to find the runnable class in. So by changing your working directory it can no longer find the class in the expected location. You can test this by setting your user.dir to "." and it will work.
user.dir is the current working directory for java. Here, you are asking it to run something from /webapp but your jar is at different location.

java run class using jawin

I'm trying to run a class that I wrote that is importing the jawin library.
My command line is as below:
java -cp C:\class_path ClassName
I'm getting:
Exception in thread 'main' java.lang.NoClassDefFoundError org/jawin/funcptr
What am I doing wrong?
Doesn't the JAR that I'm adding to the build path get into the binary file that I've compiled?
If not, then when I publish my class file how will it know to find the external JAR? What if it doesn't exist on the target computer?

Javah: Error: cannot access android.support.v7.app.ActionBarActivity

I have a problem with javah, I have read about 4 or 5 stakcoverflow posts with the error "solved" but anything works for me.
My problem:
When i execute the javah command i have this error:
Error: cannot access android.support.v7.app.ActionBarActivity
class file for android.support.v7.app.ActionBarActivity not found
What I have tried:
This is the command that I have tested:
C:\Users\MyUser\workspace3\PruebaApp\jni\include>javah -classpath ../../bin/classes;C:\Users\MyUser\AppData\Local\Android\sdk\platforms\android-14\android.jar -o ACK.h com.test.prueba.ACK
I have tried too the same command with only "/" and only "\" for separating direcotries.
I have tried it with android-11, android-14, and android-21.
I have tried to add the following external jars to my project:
"android-support-v4.jar" and "android-support-v7-appcompat.jar"
I have tried to do it creating a external build configuration with eclipse, like here: Javah Error android.app.Activity not found
Tools I'm using
I'm working with eclipse juno, on windows 8.1.
The folder from which I executed the command is {project_dir}/jni/include. I have tried it from different folders, modifying the command correctly.
The .java file that contains the native function is "ACK.java" in the package: "com.test.prueba"
In the project, the android library that I'm using is android 5.0.1
What can I do? Thanks in advance.
The native methods declared in your java class is enough for generating JNI header. In your example, the command javah's option -classpath is not very useful. Suppose com/test/prueba/ACK.java is the class you process to generate JNI header. You can change the working directory to {project_dir}\src, execute the command
javah com.test.prueba.ACK
the corresponding JNI header file com_test_prueba_ACK.h will be created in the current directory.
You should write full path of android-support-v7-appcompat.jar and android-support-v4.jar in classpath parameter.
Please have a look to my answer https://stackoverflow.com/a/52527212/2573138
which integrates in Android Studio the way described by alijandro.

Sporadic "Could not find or load main class"

I am trying to run a Java executable through the command line.
First I go to the directory the executable is located at and execute the following:
java -cp .;JARNAME-0.0.1-SNAPSHOT.jar main.class.name
This is a packaged jar so it does not have any .class files.
However, this command sporadically throws the Error: Could not find or load main class main.class.package.name error message.
Does anyone have any suggestions to get to the bottom of this?
Thanks
Last argument is class name, not package name

.jar file only works when used in Eclipse

I'm using a .jar file which I imported to Eclipse, and when I used Eclipse to run the application is works just fine.
But when I try running it from the command line with just the command java ClassName I get a NoClassDefFoundError message.
The .jar file is in the same directory as the main class I need to run.
I tried using the classpath command in the terminal
java -classpath pack.jar ClassName
but I got the same error but this time it was in the main thread
Exception in thread "main" java.lang.NoClassDefFoundError
Why does my program work in Eclipse but not on its own?
I guess you'll need to use: java -classpath .:pack.jar ClassName.
NoClassDefFoundError will come if a class was present during compile time but not available in java classpath during runtime.
Its Not Even Close To Being equal to ClassNotFoundException n u mustn't confuse them together, so u need to include the whoe path of the .jar file,
use the previously explained technique to do so, or if it was a jar file that want use frequently without using the call to java -classpath .. thing try importing the file into the OS class path directory.

Categories