Eclipse java lwjgl no lwjgl in java.library.path - java

I installed and putted lwjgl library and natives to /lib folder. On eclipse Java build path setted library location and native library location. When i try to run it on eclipse, it works, but when i export it as a runnable jar, it doesn't run, and throws error:
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:132)
at Main.start(Main.java:9)
at Main.main(Main.java:31)
Tried to set run properties VM argument to -Djava.library.path="lib/" but it doesn't work too.
P.S. Tried to put the native .dll's to same folder as the jar is and it works, but I want to .dll's to be in other folder.
Thanks!

Found an answer. You can do it with custom .bat file and put there -Djava.library.path="lib/", but mine solution is to programmaticaly do that with next line:
System.setProperty("org.lwjgl.librarypath",System.getProperty("user.dir") + "/lib/");

Have you tried using JarSplice? It is a free Java .jar packaging program found here:
Ninja Cave - JarSplice
Follow the instructions. All the documentation is on this site. Just make sure that the JAR you use for your program is just an eclipse JAR file, not a runnable jar. When you start up JarSplice, add the appropriate Jars, Natives, define your main class, and simply create a runnable JAR. No need to set up VM configurations, and also you can export to Windows.exe, and MacOSX. If all goes well, you should have a double-clickable runnable jar. Hope this helps. It's how I've packaged LWJGL games in the past :)

Related

Trying to use RXTXcomm.jar with a executable I made

I wrote a program to communicate with an arduino using the RXTXcomm.jar. It works in eclipse because I "Added External Jars" in the edit class path option.
I got the tutorial off this website: http://www.drdobbs.com/jvm/control-an-arduino-from-java/240163864. I originally tried running the command on that website to get the RXTXcomm.jar to work without having to use the eclipse work around but I couldnt get it to work (after much time and research). However, now I want to make an .exe out of my program. I used Launch4J to make an .exe and it works but, like before the eclipse work around, the serial communication aspect doesn't work.
I have thought of two fixes, I do not know the plausibility of either however:
1) Some how export my java gui to a jar file that contains the RXTXcomm.jar that was added when using eclipse work around
2) Write a script that I run once to set the computer up that will allow me to use the RXTXcomm.jar
The main goal is to create this .exe and put all the supporting files in a folder with it, with maybe a setup/readme file to get it working on any PC.
Here is my stackup when I run just the [myprogram].jar file:
java.exe -jar [myprogram].jar
java.lang.UnsatisfiedLinkError: no rxtxSerial in java.library.path thrown while
loading gnu.io.RXTXCommDriver
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: no rxtxSe
rial 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)
(AND MORE)
I have very little knowledge of what happens behind the scenes of java, I mostly understand the code only. I think that is why I am having trouble with this.
Thank you #hoijui,
I ended up just copying the rxtxSerial.dll to the same directory that the exe is run from and now it works. This directory also includes the RXTXcomm.jar as well. When making the exe in Launch4J I made a custom class path:
The "Main Class" I selected the jar I made from eclipse, then for the class path I added:
echo %CD%\RXTXcomm.jar
and
echo %CD%\rxtxSerial.dll.
I am not sure if this is needed to work but its there and it work so I am not messing with it.
Thanks for the help #hoijui

When I package my project into a .jar with eclipse, it can't find lwjgl [duplicate]

I'm making a basic game in Java using the LWJGL Library via Netbeans.
I've created a library with the lwjgl, lwjgl_util, and jinput .jar's, and I added -Djava.library.path=C:\LWJGL\native\windows to the "Run" category in the project's properties.
When I run the file in Netbeans, it runs perfectly with no issue. But when I run the .jar via double-clicking the file, nothing pops up (not even the momentary cmd error window, as far as I can tell). And when I run the file via command line, I get:
C:\Users\200160765>java -jar "C:\Users\200160765\Documents\NetBeansProjects\Game
\dist\Game.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:82)
at org.lwjgl.Sys.<clinit>(Sys.java:99)
at org.lwjgl.opengl.Display.<clinit>(Display.java:130)
at game.Draw.createWindow(Draw.java:198)
at game.Draw.init(Draw.java:214)
at game.Draw.run(Draw.java:56)
at game.Main.main(Main.java:9)
I've tried moving the DLL's and .jar library files around to the 'lib' folder in the same directory as Game.jar, and moving them to the same directory as Game.jar, but I get the same error. Could someone help me as to why I can't seem to get this working outside of netbeans?
you have to point the jvm to where the native files are located using a command line parameter -Djava.library.path="path/to/natives". You could use a batch (.bat) file to specify this and start your application for you.
Alternatively you can use a tool like JarSplice to create a single executable jar file from all your jars and at the same time include your native files inside it. It automates the tricky part of specifying the natives manually and provides a nicer end user experience.
To use JarSplice just select your game.jar, lwjgl.jar, lwjgl_util.jar, and jinput.jar in the jars tab. Then all the *.dll, *.so, *.dylib and *.jnilib files in the natives tab. Add your main class on the class tab and create the single executable jar.
LWJGL needs the native components for your particular platform to be in java.library.path. These are in the subdirectory native in the LWJGL distribution and end in .so on Linux, OSX and Solaris and .dll for windows.
When I had this issue, it was because i accidentally put the argument to specify the location of the natives (-Djava.library.path=/native/) in the field called 'Arguments' under the run category of the options panel, instead of 'vm Options'.
As seen here: http://s30.postimg.org/6f90akidt/Capture.png
And yet another way to do this is with Java Web Start (jnlp): http://lwjgl.org/forum/index.php?topic=3763.0
This makes sharing your project easier in some ways.
I had this problem and fixed it using jarSplice (http://ninjacave.com/jarsplice)
make sure you delete all of the preplaced natives in your jar before you create the fat jar, otherwise it will create a duplicate error
I also got the same error and then realised that I named the file "my_lib.zip" instead of "my_lib.jar". Maybe it may help someone.
Another thing to check:
If you are using a 32 bit JVM, you need 32 bit libraries. (Even on a 64 bit OS)
If you are using a 64 bit JVM, you need 64 bit libraries.

UnsatisfiedLinkError: no j3dcore-ogl in java.library.path

I have a project in eclipse, runs perfectly fine in the ide when I click run, but I need to export it into a runnable jar file which also works fine. But when I try to run it it throws an exception:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no j3dcore-ogl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:231)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:200)
at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:157)
at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:987)
at javax.media.j3d.VirtualUniverse.<clinit>(VirtualUniverse.java:299)
at javax.media.j3d.GraphicsConfigTemplate3D.getBestConfiguration(GraphicsConfigTemplate3D.java:321)
at java.awt.GraphicsDevice.getBestConfiguration(GraphicsDevice.java:207)
at com.sun.j3d.exp.swing.JCanvas3D.<init>(JCanvas3D.java:228)
at com.sun.j3d.exp.swing.JCanvas3D.<init>(JCanvas3D.java:178)
at mainproject.MainPanel.<init>(MainPanel.java:72)
at mainproject.MainWindow.<init>(MainWindow.java:42)
at mainproject.MainWindow.main(MainWindow.java:23)
I have been googling it for 2 days now, tons of results, none helpful.
I export it by going to file->export->java->Runnable jar file->i bubble extract required libraries into generated jar, choose the correct configuration, save the file in a specified folder, then it saves just fine. Or at least so I think. The java.library.path goes to the jre lib folder, but when i run it in eclipse it goes to the .so for j3d, i tried changing it using System.setProperty but to no success. I have a feeling that is the problem, but when I tried to fix it nothing happened. I'm using the most up to date java3d library (1.5.2 I believe).
Any suggestions?
If I set
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/jni
it works.

load java native file lib

I would like to use some native files and use some files out of an android project. I need this files for my own java project and need to import the lib.
I am trying to load the lib with:
static
{
System.loadLibrary("mrclient_java");
}
The lib file "libmrclient_java.so" is in this folder: "/libs/armeabi/".
When I run the project following error appears:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no mrclient_java 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)
I dont know how to configure the CLASSPATH or whatever to solve this problem.
I am not using android for this project. The android project itself runs perfectly.
EDIT:
I found this Question: How to set the java.library.path from Eclipse, but the same error still appear.
You have to add java.library.path to your command line that runs java. Something like the following:
java -cp YOURCLASSPATH -Djava.library.path=/libs/armeabi/ com.compnay.Main
Classpath is for loading java classes only. Library path is for loading native libraries.

How to create an exe file in java

Hi I want to create an exe file for my java app.
I tried with some third party softwares JEXECreator, successfully created the exe file and its working fine in my system, when I tried with another machine, it’s not working. I got the following error
* The error occurred while running the application. The exit code is 0x10000223.
* Contact the vendor of the application for troubleshooting.
java.lang.ClassNotFoundException: com.sample.SampleMain
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)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.ucware.JEXEClassLoader.run(Unknown Source)
at com.ucware.JEXEClassLoader.main(Unknown Source)
**************************************
I know there is something wrong with the classpath which I set.
Actually I want to create the exe file myself without using any third party software.
I found the steps in lot of sites
Created the manifest file named Sample.mft with following contents
Manifest-Version: 1.0
Main-Class:
Class-path:
In this I have some doubts,
How the Main-Class should be added, with the full package name (com.sample.SampleMain) or the class name alone (SampleMain) or with the extension (SampleMain.class)
How the class-path should be added, I have 4 java classes and 2 jars in my project. How to add all these in the class path, and do I need to add the java jdk in classpath.
Where the manifest file should be saved
What should be the manifest file extension (mf or mft)
In command prompt from which directory I should create the exe file (from my project folder or src folder or the folder which contains all the java classes)
What’s the syntax should be used while creating jar in command prompt
(jar cmf Sample.mf Sample.jar Sample1.class Sample2.class Sample3.class Sample4.class jar1.jar jar2.jar) like this or (jar cvfm Sample.jar sample.mf *.class)
When I did something like this I am getting a jar instead of exe file, When I run the jar in command prompt using "java -jar sample.jar" then I am getting class not found exception".
Actually how to create an exe file instead of jar file, that means just by double clicking that exe file, should run my app in any machine.
Can anyone help me to do this?
Thanks in advance.
I use the Ant tool under Eclipse IDE to work with InnoSetup and Launch4J to create the EXE and its installer which it also manages the classpath...
A guide? You can refer to:
http://www.eteks.com/tips/tipCreationExe.html (in French)
Can't speak for JEXECreator, but I can recommend JSmooth (http://jsmooth.sourceforge.net/). I've successfully used it for several projects (e.g. this SWT based Java app).
Personally, I like JSmooth. That is just wrapping. This means it is still a Java application. When executing the exe, it will unpack the jar to a temporary folder and then execute it with javaw -jar ...
A second option is gcj. But that is absolutely a bad choice. That doesn't wrap the jar in an exe, but it really compiles it to native system code. But this slows down your application very much. You can check some results of my timing on this topic.
I had some positive experience with Excelsior JET. Unlike gcj it actually works and execution times are faster than that of an executed .jar file. The downside is that it's not for free.
Well I will recommend you to create one bash file instead of doing complex things and by double clicking on it you can run your application.Yeah but you cant change its icon but there are many free tools are available by using which you can easily convert bash file to exe.
To create an exe file, I use launch4j. Launch4j converts the jar file into exe file and if I wanna pack it for the installer, I use InnoSetup. For me, that exe created by launch4j works on pcs.

Categories