i am using a third part SDK with my java application.The providers of sdk provided me exe file that i installed and one java project.I installed the exefile.
Now when i run the code i get a dialog box showing error
Excepting a absulut path for library AKSSDK.dll
No AKSSDK in java.library.path
could not load load library AKSSDK
how do i resolve it?
You need to run java with the following configuration:
java -Djava.library.path={where your library is}
Note the above is the directory where your library is, not the full path name of the library!
You have to add AKSSDK.dll to your PATH environment variable.
It would look like this:
echo %PATH%
C:\xyz\;C:\other\etc\etc;C:\Your\Path\To\AKSSDK.dll
EDIT
To modify your environment variable you have to go to:
MyComputer/RightClick/Properties/Advanced/EnvironmentVariables
(source: vlaurie.com)
And modify the existing Path under System variables
See this tutorial for more details: http://vlaurie.com/computers2/Articles/environment.htm
I have had problems with the white space of ( Program files ) in the past. If possible install your SDK on something like C:\SondaSDK or C:\You\SondaSDK
That way you shouldn't have problems.
You can manually set the path to this value by starting with
java -Djava.library.path=PATH_TO_LIBRARY
Related
I'm starting off with jni and trying to get a simple HelloWorld example working. I'm having a linkage error which I'm guessing has to do with my native library not pointing to the correct file path.
I have to use the command:
java -Djava.library.path= ??
What do I set this to? All my so files are in a app/src/main/libs/armeabi/libHelloJni.so , libs/x86/libHelloWorld.so, and so on.
I'm currently doing:
static {
System.loadLibrary("HelloJni")
}
The .so files should be placed in app/src/main/jniLibs/ folder. In your case, it should be app/src/main/jniLibs/armeabi/libHelloJni.so.
I'm sure app's build.gradle is OK and my *.so also OK. After reading official doc my problem is from Android Studio 3.0 and encounter this problem
Go to Run -> Edit Configurations -> Profiling, and disable "Enable advanced profiling".
This works for me
I wrote a program that works on my laptop perfectly, but I really want it to work on a server that I have. Using NetBeans, I've clean and built the project. I copied the contents of the folder dist on my server but I cannot seem to get to work by using command
java -jar nameOfFile.jar
I get the error
java.lang.NoClassDefFoundError: org/....
I have been doing some reading and from what I gather is that I need to pretty much specify where the libraries that I've used are located. Well they are located in a subfolder called lib.
Question:
So what would I need to do in order to be able to run my jar?
CLASSPATH is an environment variable that helps us to educate the Java Virtual Machine from where it will start searching for .class files.
We should store the root of the package hierarchies in the CLASSPATH environment variables.
In case of adding or using jar libraries in our project, we should put the location of the jar file in the CLASSPATH environment variable.
Example: If we are using jdbc mysql jar file in our java project, We have to update the location of the mysql jar file in the CLASSPATH environment variable. if our mysql.jar is in c:\driver\mysql.jar then
We can set the classpath through DOS in Windows
set CLASSPATH=%CLASSPATH%;c:\driver\mysql.jar
In Linux we can do
export CLASSPATH=$CLASSPATH:[path of the jar]
Hope it helps!
Try that:
java -classpath "$CLASSPATH:nameOfFile.jar:lib/*" path.to.your.MainClass
What this does is setting the classpath to the value of $CLASSPATH, plus nameOfFile.jar, plus all the .jar files in lib/.
Classpath
A compiler(e.g. javac) creates from .java - .class files and JVM uses these .class files.
classpath - local codebase[About] - points on the root of source. classpath + import_path = full path
For example for MacOS
//full path
/Users/Application.jar/my/package/MainClass
//classpath
/Users/Application.jar
//import_path
my.package.MainClass
Android classpath
ANDROID_HOME/platforms/android-<version>/android.jar
//e.g
/Users/alex/Library/Android/sdk/platforms/android-23/android.jar
When you use a META-INF/MANIFEST.MF file to specify the Main-Class dependencies must be specified in the manifest too.
The -jar switch ignores all other classpath information - see the tools docs for more.
You need to set class path using
The below works in bash .
This is temporary
set CLASSPATH=$CLASSPATH=[put the path here for lib]
If you want it permanent then you can add above lines in ~/.bashrc file
export CLASSPATH=$CLASSPATH:[put the path here for lib]:.
You have 2 questions, one is the "title question" and another is the "foot note question" after elaborating your problem.
Read this documentation bellow to get a better understanding of CLASSPATH.
https://docs.oracle.com/javase/tutorial/essential/environment/index.html
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html
This is fast and straight forward for what you need.
For your first question, this will do:
The documentation recommends us to set a classpath for every application we are running at the moment using (use in the command-line):
java -classpath C:\yourDirectoryPath myApp
For your second question, look this exercise in the java documentation. It seems to be the same problem:
https://docs.oracle.com/javase/tutorial/essential/environment/QandE/answers.html
Answers to Questions and Exercises: The Platform Environment
Question 1.A programmer installs a new library contained in a .jar file. In order to access the library from his code, he sets the CLASSPATH environment variable to point to the new .jar file. Now he finds that he gets an error message when he tries to launch simple applications:
java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: Hello
In this case, the Hello class is compiled into a .class file in the current directory — yet the java command can't seem to find it. What's going wrong?
Answer 1. A class is only found if it appears in the class path. By default, the class path consists of the current directory. If the CLASSPATH environment variable is set, and doesn't include the current directory, the launcher can no longer find classes in the current directory. The solution is to change the CLASSPATH variable to include the current directory. For example, if the CLASSPATH value is c:\java\newLibrary.jar (Windows) or /home/me/newLibrary.jar (UNIX or Linux) it needs to be changed to .;c:\java\newLibrary.jar or .:/home/me/newLibrary.jar."
I'm configuring the JPL right now, and wanna work with swi-prolog using java.
I downloaded the newest stable version of SWI-Prolog, which is 6.2.0, and installed in D:\swipl
First, I added the following path to the PATH virable: D:\swipl\bin, which should include all dll files needed.
Then, I added the following path to the CLASSPATH virable: D:swipl\lib\jpl.jar, which should be the jar file needed.
When I tried to run the versions example provided, I got the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: jpl.fli.Prolog.thread_self()I
at jpl.fli.Prolog.thread_self(Native Method)
at jpl.Query.open(Query.java:286)
at jpl.Util.textToTerm(Util.java:162)
at jpl.Query.Query1(Query.java:183)
at jpl.Query.<init>(Query.java:176)
at Versions.main(Versions.java:11)
After searching online, I found that many people just get java.lang.UnsatisfiedLinkError: no jpl in java.library.path which is because of the setting for the PATH variable, rather than the error I get here: java.lang.UnsatisfiedLinkError: jpl.fli.Prolog.thread_self()I (and yes, there is a "I" at the end of the line).
Has anyone gotten this error before? I've tried several previous version of SWI-Prolog, but also got other kinds of errors. I'm using Eclipse IDE for Java development -- have I missed anything?
I've sent the problem to the official mailing list (swi-prolog#lists.iai.uni-bonn.de) provided by swi-prolog.org, and luckily someone helped me to prove that there are some problems in the version 6.2.0. We then both tried the version 6.0.2, and it works perfectly. He mentioned that (and I noticed that) there is no swipl.dll in the bin folder of the version 6.2.0, which MAY causes the issue.
I've already reported the issue to the staff via Email, and at least for now, I suggest that people who want to configure JPL should download the version 6.0.2. Three things to remember:
add a new variable SWI_HOME_DIR under system variables in environment variables, and set the path to the place where you installed the SWI-Prolog (Mine is D:\swipl);
Add the path %SWI_HOME_DIR%\bin to your PATH variable, rather than use something like "D:\swipl\bin". (Otherwise [FATAL ERROR: Could not find system resources] will occur)
Add the path %SWI_HOME_DIR%\lib\jpl.jar to your PATH variable, rather than use something like "D:\swipl\lib\jpl.jar". (Otherwise [FATAL ERROR: Could not find system resources] will occur)
If you are using Eclipse for Java development, it seems that you DO NOT need to configure in your IDE. As long as you follow the 3 steps above and add the correct jar file as an external library, it should be fine.
I'm not sure whether the temporary solution works for everyone, but definitely, everyone who has the issue should try this method first. As long as the issue in the version 6.2.0 has been figured out, I'll add some comments here.
BTW, as far as I know, until now, people who have the issue are using 32-bit Windows.
Try adding your path to java.library.path via Run > Run Configuration > [project name] and add the following under "VM Arguments" tab.
-Djava.library.path="D:\swipl\bin;."
Furthermore, under the "Environment" tab, add the following:
VARIABLE: PATH
VALUE: D:\swipl\bin;${env_var:PATH}
After that, go to Project > Properties > Java Build Path, select "Libraries" tab.
Click "Add External JARS.." and find your jpl.jar.
Great Great Great, second answer is the solution
create SWI_HOME_DIR variable to set the swi prolog instalation directory
SWI_HOME_DIR ------- C:\Program Files\swipl
set PATH to point to the library and bin like this
PATH ------ %SWI_HOME_DIR%\bin;%SWI_HOME_DIR%\lib\jpl.jar
This fix my problem "Exception in thread "main" java.lang.UnsatisfiedLinkError: no jpl in java.library.path windows" it is a little bit rare but it works find.
I had the same problem. In addition to set the PATH, you need to verify if the installed SWI program has the same architecture (32 or 64) of your JVM.
I am using eclipse and getting the below error when I try to access a native method from a ExtractImage.dll file-
java.lang.UnsatisfiedLinkError: getVertices
at com.coimp.application.ExtractImage.getVertices(Native Method)
I have added the dll to below paths -
C:\Program Files\Java\jre1.5.0_10\bin;
. //current workspace
C:\WINDOWS\system32;
C:\WINDOWS;
and I have used this method to load the library -
System.loadLibrary("ExtractImage");
Also tried with -
System.load("c:\ExtractImage.dll");
Adding the .dll file to NativeLibrary path
The same code works on my web application.
Geeks, any guesses to fix this problem ?
Thanks for upcoming support.
In the "Run Configuration..." options in the "Arguments" tab specify in "VM Arguments" "-Djava.librar.path=YOUR_DIR_TO_DLL"
If the library has dependencies with other DLLs not present in the PATH, you should also include those directories (separated by ;)
Update
If that fails too you can modifiy PATH environment variable (in tab "Environment"). I would recommend you that you edit the variable (adding your directories) an leave the option "Append environment to native environment" selected (radio buttons at bottom).
I have Windows 7, installed jdk1.7.0 and its supporting jre7.
My problem is compilation part works perfectly, but while running the Java program I get this error saying:
"Could not find or load main class"
I am storing all my programs in javalab folder. I have set the path to it. Procedure looks like this:
C:\Users\user>cd\
C:\>cd javalab
C:\javalab>autoexec.bat
C:\javalab>set path=C:\Program Files\Java\jdk1.7.0\bin
C:\javalab>javac p1.java
C:\javalab>java p1
Error: Could not find or load main class p1
C:\javalab>
I was having a similar issue with my very first java program.
I was issuing this command
java HelloWorld.class
Which resulted in the same error.
Turns out you need to exclude the .class
java HelloWorld
Try:
java -cp . p1
This worked for me when I had the same problem, using Fedora (linux)
Simple way to compile and execute java file.(HelloWorld.java doesn't includes any package)
set path="C:\Program Files (x86)\Java\jdk1.7.0_45\bin"
javac "HelloWorld.java"
java -cp . HelloWorld
pause
javac should know where to search for classes. Try this:
javac -cp . p1.java
You shouldn't need to specify classpath. Are you sure the file p1.java exists?
I had almost the same problem, but with the following variation:
I've imported a ready-to-use maven project into Eclipse IDE from PC1 (project was working there perfectly) to another PC2
when was trying to run the project on PC 2 got the same error "Could not find or load main class"
I've checked PATH variable (it had many values in my case) and added JAVA_HOME variable (in my case it was JAVA_HOME = C:\Program Files\Java\jdk1.7.0_03)
After restarting Ecplise it still didn't work
I've tried to run simple HelloWorld.java on PC2 (in another project) - it worked
So I've added HelloWorld class to the imported recently project, executed it there and - huh - my main class in that project started to run normally also.
That's quite odd behavour, I cannot completely understand it.
Hope It'll help somebody. too.
i guess that you have a different class name in p1.java
Check you class name first. It should be p1 as per your batch file instruction. And then check you package of that class, if it is inside any package, specify when you run.
If package is x.y
java x.y.p1
Here is my working env path variables after much troubleshooting
CLASSPATH
.;C:\Program Files (x86)\Java\jre7\lib\ext\QTJava.zip;C:\Program Files (x86)\Java\jdk1.6.0_27\bin
PATH <---sometimes this PATH fills up with too many paths and you can't add a path(which was my case!)
bunchofpaths;C:\Program Files (x86)\Java\jdk1.6.0_27\bin
Additionally, when you try to use the cmd to execute the file...make sure your in the local directory as the file your trying to execute (which you did.)
Just a little checklist for people that have this problem still.
I've had similar problems. If you work with Eclipse, you need to go to the folder where you have your src/ folder... If you used a package - then you use
javac -cp . packageName/className
which means if you've had a package named def and main class with name TextFrame.java you'd write
javac -cp . def/TextFrame
omitting the trailing .java extension, and then you run it with the
java def/TextFrame
and if you have have arguments, then you need to supply it with arguments corresponding to your program.
I hope this helps a bit.
First, put your file *.class (e.g Hello.class) into 1 folder (e.g C:\java). Then you try command and type cd /d C:\java. Now you can type "java Hello" !
You might have the CLASSPATH environment variable already added!!
Use following to avoid further usage of -cp . in java -cp . CLASSFILE
Add . to CLASSPATH in system properties->environment variables or by cmd
set CLASSPATH=%CLASSPATH%;.;
I faced a similar problem in Eclipse. Whenever I clicked on the Run button it gave me the message, "Error: Could not find or load main class". But when I right click on the java file in the project explorer and Run As Java configuration, it works perfectly.
I think this is because it tries by default to run it in some other configuration which causes problems.
Hope this answer helps some.
If you have a single .java file to compile using command-line , then remove
topmost package parts from the code, the compile again, it will work.
This worked for me.
Sometimes what might be causing the issue has nothing to do with the main class. I had to find this out the hard way, it was a referenced library that I moved and it gave me the:
Could not find or load main class xxx Linux
I just delete that reference and added again and it worked fine again.
i had
':'
in my project name e.g 'HKUSTx:part-2'
renaming it 'HKUSTx-part-2' worked for me
You can use NetBeans IDE which is free to download and use "Open Source". You can even do other programming language in this IDE. The latest of which it supports HTML5. This makes your programming easier. If you're not familiar with it choose a book that is NetBeans integrated like Sams Teach Yourself Java in 24 Hours