Trying to use RXTXcomm.jar with a executable I made - java

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

Related

UnsatisfiedLinkError loading OpenCV (Linux)

I need to create a runnable jar in Windows with Eclipse and start it with Linux
I'm getting an unsatisfiedLinkError while loading OpenCv. I have edited the correct library path for a Linux computer in Eclipse and finally created a runnable jar. When I start the *.jar file in linux and get the following error.
Exception in thread "main" java.lang.UnsatisfiedLinkError: no
opencv_java2411 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1889)
at java.lang.Runtime.loadLibrary0(Runtime.java:900)
at java.lang.System.loadLibrary(System.java:1087)
Basically i have two question.
1. How can i get the loaded library path at runtime?
2. Is it possible that the chosen way is not the right way to handle the problem?
Thanks
One important this to keep in mind for loading linux libraries with System.loadLibrary, omit the lib prefix in the library name, for instance, if the library name is libxyz.so, your call would be:
System.loadLibrary("xyz");
Set the path of OpenCV in the variable LD_LIBRARY_PATH. You can do it in the shell where you run the "jar". Use export command.

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.

build java project into executable

How can i make an executable of my project in Java?
I tried to right click on my project and selected export .
the problem is that the exported jar file wont open when I execute it! Have I missed something? And is there a way to make an .exe executable from my project?
when I execute the jar file in cmd it says :
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 org.newdawn.slick.AppGameContainer$1.run(AppGameContainer.java:39)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.AppGameContainer.<clinit>(AppGameContainer.java:36)
at JavaGame.Game.main(Game.java:34)
UnsatisfiedLinkError indicates that you're missing a native library (usually a .dll file on Windows, or .so file on Linux). You'll need to do one of the following:
Not recommended: Copy the native library to a location on the default java.library.path (on Windows, this includes C:\Windows\system32)
Not recommended: Copy the native library to a directory, then run your program with java -Djava.library.path=dir/containing/library -jar <jarfile>
Recommended: Bundle the DLL in your jarfile, then modify your code to extract the DLL to a temporary directory and load it using System.load or System.loadLibrary.
You can use either of the first two solutions above as a quick hack to get it working, but neither of those solutions is very good. The best solution from a deployment standpoint is #3 above.
In your case, you're using the Lightweight Java Game Library, or lwjgl as referenced in your UnsatisfiedLinkError. So you'll need to include any DLL(s) that come with lwjgl.
When you unzip lwjgl, you'll notice that it has a native directory with a subdirectory for each supported platform. Here is a listing of lwjgl's Windows DLLs:
To implement solution #3 above and make your executable jarfile cross-platform:
in your project/jarfile, create a separate directory for each platform
put all the native libraries for each platform in the appropriate directory (it may be helpful to put them in the same directory as some utility class that you'll later use to extract them)
when you export your program to a jarfile, make sure the native libraries are included
look up the platform/operating system (e.g., System.getProperty("os.name"))
in your Java code (probably in your main method or some utility method), create a temporary directory
for whatever platform you looked up in step 3, extract the appropriate native libraries into the directory you created in step 4 (hint: use Class.getResourceAsStream to get an InputStream, then use Files.copy to extract it to a file)
for each library you extract in step 5, call System.load("path/to/library_file")
See https://stackoverflow.com/a/1611367/44737 for a nice example including code.
You can either package everything in a jar manually using the jar command line tool or you can automate the process of packaging your jar using tools like Ant, Maven or Gradle.
Once you have your class files properly packaged in jar file, you can execute them by creating a script file appropriate for your operation system. For instance a batch file in windows or a bash file in Linux.
All you have to do is invoke the java command and provide your class path and the name of your application entry point.
#!/bin/bash
java -cp myApp.jar com.my.app.Main
And that's it. You execute your application by invoking that script.
Additionally, you can make arrangements to create an executable jar, by means of defining a MANIFEST file for you jar file. In that manifest file you can place a property Main-Class that indicates your application entry point and you can define another property called Class-Path which allows you to specify a list of other jars needed by your application.
See Running Jar-Packaged Software.
If you package your jar this way, some operating systems allows you to execute the application by simply double-clicking the jar.
But most probably, you still will need to create a script, just a bit different this time:
#!/bin/bash
java -jar myApp.jar
See the Java Tutorial: Packaging Applications in Jar Files.
Ultimately, if you really, really need to create an executable file, and if you're working on windows, you may consider a tool like WinRun4j.

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.

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