Compiling and running in java. Giving me errors - java

compiled my project in netbeans IDE and when I run the jar nothing happens just gives me a error occured while trying to run it. I think I found the problem just not sure how to fix it. Help please!
This is what happens when I check the jar in CMD
C:\Users\Mac\Desktop>java -jar dist\pong.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: no lwjgl in java.libr
ary.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.lwjgl.Sys$1.run(Sys.java:73)
at java.security.AccessController.doPrivileged(Native Method)
at org.lwjgl.Sys.doLoadLibrary(Sys.java:66)
at org.lwjgl.Sys.loadLibrary(Sys.java:95)
at org.lwjgl.Sys.<clinit>(Sys.java:112)
at org.lwjgl.opengl.Display.<clinit>(Display.java:135)
at mw.Main.initDisplay(Main.java:36)
at mw.Main.main(Main.java:25)
C:\Users\Mac\Desktop>
When I check the manifest file it's pretty much empty:
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

when I check the jar in CMD C:\Users\Mac\Desktop>java -jar dist\pong.jar
You need to use the -cp switch while running the jar using the java command.
Documentation
You can easily google to find more examples on how does -cp works.

You need to create a library and add a reference to it in your project
See Setting Up LWJGL with Netbeans
At a guess I'd say you are missing step 5 from Setting Up a Project to Use LWJGL in NetBeans
Finally, you need to tell NetBeans where the Native Libraries (i.e, DLL, JNILIB, DYLIB, SO files) are for your system so that the natives are linked when running.
Select the Run category and then type the following into the VM Options, replacing what is in bold to suit your system:
-Djava.library.path=<lwjgl-X.X path>/native/<linux|macosx|solaris|windows>
Update: Didn't realise you were doing it from the command prompt. You say you are running
java -jar dist\pong.jar
You need to add the -D option so something like this:
java -Djava.library.path=<lwjgl-X.X path>/native/windows -jar dist\pong.jar

Related

Export a runnable JAR and include .so native library

I'm writing a java application (on Linux OS) which accesses the webcam and display a video on a JPanel. I'm using openCV libraries in order to obtain it (also because I would like to add some image processing code).
I followed this guide to compile the openCV library for Java
and the only way I could make it work was by creating an user library linked to the folder where I have the corresponding jar file.
(I tried to directly import the jar file but I have some runtime exception, so I gave up).
This is my situation.
Now I have a working application (if I execute it from within Eclipse), and I want to export it as a single jar (or something executable outside Eclipse). I tried to achieve this by selecting these options.
The problem is that now I want test if the jar works by executing the following command from terminal (where Untitled.jar is the name of the exported code):
java -jar Untitled.jar
but I receive this error (I bolded the main problem):
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498) at
org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader.main(JarRsrcLoader.java:58)
Caused by: java.lang.UnsatisfiedLinkError: no opencv_java331 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
myRefreshTest.Main.main(Main.java:8)
opencv_java331 is the name of the .so library generated after building openCV for Java (opencv_java331.so)
I tried several way to export my program, also by selecting the 3rd option in the Eclipse export popup ("Copy required libraries into sub-folder next to the generated JAR) and then executing
java -cp Untitled_lib/opencv-331.jar -jar Untitled.jar
but terminal returns this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no
opencv_java331 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
myRefreshTest.Main.main(Main.java:8)
So, the problem is clear, it can't find the openCV .so library.
I tried to use also option -Djava.library.path but it is not working (or at least I'm not using it properly)
I'm not a Java expert and I cannot understand how to fix this problem. Does anyone know how to fix this issue?

Error while running my jar outside of the ide using command line and external lib

I got a programm which is working on my ide (Eclipse Luna Service Release 2 (4.4.2)). Now i want to execute it without Eclipse to be able to run it on others computer.
I exported it from eclipse using export projet into a jar file, a specified this manifest:
Manifest-Version: 1.0
Main-class: RecupPhoto
Class-path: opencv-300.jar
Both files, RecupPhoto.jar and opencv-300.jar are in the same folder, i already checked the java path, the jre and jdk.
My problem is when i execute:
java -jar RecupPhoto.jar
with a .bat file inside the jar folder i got this error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java300 in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at Ihm.<init>(Ihm.java:89)
at RecupPhoto.main(RecupPhoto.java:10)
I'm not expert on errors etc but i understand that there is an error with "opencv_java300", but i don't understand this error because i didn't get this import with a "java" in the middle of the name.
Here is the loadlibrary from the error, in case it could help:
System.loadLibrary(org.opencv.core.Core.NATIVE_LIBRARY_NAME);
(core is a package from opencv library).
So any idea/help will be welcome! (and sorry for my poor english)
I was missing the path to dll in my bat file,
new call is:
java "-Djava.library.path="C:\opencv\build\java\x64 -jar RecupPhoto.jar

netbeans jar build file not opening

I have build my project using OpenCV. When I run my project through netbeans it runs fine.. but when I create its jar file via Clean and Build it doesn't open.
it displays a message in output screen when it is build that is..
To run this application from the command line without Ant, try:
java -jar "C:\Users\Rafi Abro\Documents\NetBeansProjects\WebCam\dist\WebCam.jar"
I also tried to open my project through this command..
java -jar WebCam.jar
but it displayed error below:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java2410 in
java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at javaanpr.Main.main(Main.java:154)
please can anyone help me through out this problem..
Thanks
This is because you have included VM option path in netbeans. and Netbeans Automatically calls it whenever it is executed.
now when you are trying to run command. i.e.
java -jar WebCam.jar
there is not path defined in command, thatsy you are getting that error..
try this command:
java -Djava.library.path="C:\OpenCV\opencv\build\java\x86" -jar WebCam.jar
hope this will help you.!

Java Path zeromq setting

I am using MAC OSX
I already follow the instruction on 0mq official site to install
when i compile it , i dont get any error.
But when i run the following command
java -classpath /Users/john/jzmq/ -cp $(lein classpath) storm.starter.WordCountTopology
I got the following error.
java.lang.UnsatisfiedLinkError: no jzmq in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1878)
at java.lang.Runtime.loadLibrary0(Runtime.java:849)
at java.lang.System.loadLibrary(System.java:1087)
at org.zeromq.ZMQ.<clinit>(ZMQ.java:34)
at storm.starter.spout.RandomSentenceSpout.nextTuple(RandomSentenceSpout.java:39)
at backtype.storm.daemon.executor$fn__3985$fn__3997$fn__4026.invoke(executor.clj:502)
at backtype.storm.util$async_loop$fn__465.invoke(util.clj:377)
at clojure.lang.AFn.run(AFn.java:24)
at java.lang.Thread.run(Thread.java:724)
My setting
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home
I also have zmq.jar under
/usr/local/lib and
/usr/local/share/java
I read through all the google search I can found. Still no crew why my one is not working
In addition to setting the JAR classpath, you need to specify where the jzmq .so library files reside. Did you build zmq, libzmq, and jzmq exactly as described in the directions? If so, you should see the .so library files in /usr/local/lib and zmq.jar in /usr/local/share/java, confirm that, then logout/login based on this, then try this:
java -Djava.library.path=/usr/local/lib -cp "/usr/local/share/java/zmq.jar:/Users/john/jzmq/<your jar here>" storm.starteer.WordCountTopology
Hope it helps

Add Jar File to Buildpath in Windows Command Line

Im quite annoyed at having to ask this but I cant get it to work. Currently I have a project with:
5 Classes in the src/ folder
2 JARS named profiles.jar and
classifier.jar in the root folder
I want to create a "makefile?" or "batch file?" to compile and run these classes FROM THE WINDOWS COMMAND LINE, but first add the jars to the buildpath? Im not sure how I go about this
When I try to do it, it says that the class is not found, most likely due to me not adding the jars to the buildpath correctly. What are the commands I need to use to run this in command prompt?
Thanks
Philip
EDIT
Thanks for the help, Im having alot of trouble getting it to work tho
Currently I have a project with 5 classes in the src folder, and 2 jars in the jar folder
Here are the commands
Im running:
set
CLASSPATH=C:\wamp\www\news\UserProfiling\jars\classifier.jar
;C:\wamp\www\news\UserProfiling\jars\profiles.jar
Then from the root folder, Im running:
javac src/*.java
Then:
java -cp ./src:./jars/*
src/Interaction
Interaction is the main class, Im getting all sorts of noclassfound errors, am I doing something wrong?
Many thanks Philip
THE ERROR
java -cp ./src:./jars/* Interaction
Exception in thread "main"
java.lang.NoClassDefFoundError:
Interaction Caused by:
java.lang.ClassNotFoundException:
Interaction
at java.net.URLClassLoader$1.run(Unknown
Source)
at java.security.AccessController.doPrivileged(Native
Method)
at java.net.URLClassLoader.findClass(Unknown
Source)
at java.lang.ClassLoader.loadClass(Unknown
Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown
Source)
at java.lang.ClassLoader.loadClass(Unknown
Source)
at java.lang.ClassLoader.loadClassInternal(Unknown
Source) Could not find the main class:
Interaction. Program will exit.
In version older than or equal to Java version 5 you must specify each jar individually, and the root of your source, on your classpath e.g.
java -cp a.jar:b.jar:c.jar:./src MainClass
In version 6 you can use wildcards for the jars e.g.
java -cp ./src:* MainClass
but it might be cleaner putting your jars into a sub directory e.g.
java -cp ./src:./jars/* MainClass
So basically, your makefile or start script needs to construct a command like one of the above.
More info - Sun docs (v6)
Update - in response to your second edit, you need to specify the full main class name, so if the class is in a package called 'com.mypackage.MainClass' then you need to do:
java -cp ./src:./jars/* com.mypackage.MainClass
I'd also suggest getting the command working as a standalone command first, before getting the whole script running. By removing moving parts it will be faster to debug and easier to see what's going on.
I would suggest you take a look at ant or maven. Ant is a solution to do pretty much straightforward what you want to do, maven is not as straightforward but has its advantages when it comes to managing dependencies.
About your second question : if you use
java -cp ./src:./jars/* src/Interaction
it will try to launch the class src/Interaction, which does not exists. src is already in your classpath, so you just have to do
java -cp ./src:./jars/* Interaction
Found your problem, I think.
javac src/*.java
java -cp ./src:./jars/* src/Interaction
This problem plagues many beginners: You need to run javac and java from the directory where your source tree starts. In your case, that directory is src. Since src does not appear in your package names, it should also not appear in your compile/execution paths.
So you should
cd UserProfiling/src
and run
javac *.java
and
java -cp .:../jars Interaction
from there.

Categories

Resources