How to run SWT application from SWT application? - java

I have two SWT application. From app 1, I call app2:
Runtime.getRuntime().exec("App2.bat");
App2 is runned but when getting display, it throws exception:
java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-win32-3740 in java.library.path
no swt-win32 in java.library.path
C:\Documents and Settings\Tran Dinh Thoai\.swt\lib\win32\x86\swt-win32-3740.dll: The referenced assembly is not installed on your system
Can't load library: C:\Documents and Settings\Tran Dinh Thoai\.swt\lib\win32\x86\swt-win32.dll
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at com.escapenotes.updater.Checker.run(Checker.java:58)
at com.escapenotes.updater.Runner.main(Runner.java:20)
When I call app2 (run App2.bat) from command line, it run well but it throws exception when running from app1. How can I run app2 from app1?
This is content of App2.bat:
#echo off
set JH=C:\Program Files\Java\jre6
set CP=C:\Data\Projects\EscapeNotes\extensions\Updater\bin
set XNP="%CP%";"%CP%\commons-logging-1.1.1.jar";"%CP%\aws-java-sdk-1.0.007.jar";"%CP%\commons-codec-1.4.jar";"%CP%\commons-httpclient-3.0.1.jar";"%CP%\jsoup-1.6.2.jar";"%CP%\log4j-1.2.8.jar";"%CP%\text.jar";"%CP%\jface.jar";"%CP%\jfacetext.jar";"%CP%\osgi.jar";"%CP%\runtime.jar";"%CP%\swt.jar"
"%JH%\bin\java.exe" -cp %XNP% com.escapenotes.updater.Runner %1
When I added -Djava.library.path
#echo off
set JH=C:\Program Files\Java\jre6
set CP=C:\Data\Projects\EscapeNotes\extensions\Updater\bin
set XNP="%CP%";"%CP%\commons-logging-1.1.1.jar";"%CP%\aws-java-sdk-1.0.007.jar";"%CP%\commons-codec-1.4.jar";"%CP%\commons-httpclient-3.0.1.jar";"%CP%\jsoup-1.6.2.jar";"%CP%\log4j-1.2.8.jar";"%CP%\text.jar";"%CP%\jface.jar";"%CP%\jfacetext.jar";"%CP%\osgi.jar";"%CP%\runtime.jar";"%CP%\swt.jar"
"%JH%\bin\java.exe" -Djava.library.path="C:\Data\Projects\EscapeNotes\extensions\Updater\bin" -cp %XNP% com.escapenotes.updater.Runner %1
Although there is C:\Data\Projects\EscapeNotes\extensions\Updater\bin\swt-win32-3740.dll, I got exception:
java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
C:\Data\Projects\EscapeNotes\extensions\Updater\bin\swt-win32-3740.dll: The referenced assembly is not installed on your system
no swt-win32 in java.library.path
C:\Documents and Settings\Tran Dinh Thoai\.swt\lib\win32\x86\swt-win32-3740.dll: The referenced assembly is not installed on your system
Can't load library: C:\Documents and Settings\Tran Dinh Thoai\.swt\lib\win32\x86\swt-win32.dll
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at com.escapenotes.updater.Checker.run(Checker.java:58)
at com.escapenotes.updater.Runner.main(Runner.java:20)

From the exception it looks like swt-win32 library is not defined by the java.library.path environment variable. In your "App2.bat" please provide it by the -D option like:
java -Djava.library.path=[path to your library]

Take a look at SnippetLauncher in the snippet project of the SWT sources. It demonstrates how to programmatically launch snippets.
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/tree/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/SnippetLauncher.java
The above works across platforms btw. I've used it on Linux and Windows.
Another thing to try is to copy the run-configuration of a terminated snippet. In the debug view, see the properties of a terminated run, it shows the command that was used to run the snippet. (I do this on Gtk, not sure if it works well on Windows).
Let me know if that solves things for you or if you have further questions.

Related

java openmaple connection with eclipse

test.java simple example for openmaple
Hello buddies!
I have tried so many times to connect java to maple using openmaple but get below error. please help me, I'm using Eclipse as java editor. thanks in advance
`java.lang.UnsatisfiedLinkError: no jopenmaple in java.library.pathError loading libraries: java.lang.UnsatisfiedLinkError: no jopenmaple 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 com.maplesoft.openmaple.Engine.<clinit>(Unknown Source)
at test.main(test.java:23)
Exception in thread "main" java.lang.UnsatisfiedLinkError: com.maplesoft.openmaple.Engine.getKernel([Ljava/lang/String;Lcom/maplesoft/openmaple/EngineCallBacks;Ljava/lang/Object;Ljava/lang/Object;)J
at com.maplesoft.openmaple.Engine.getKernel(Native Method)
at com.maplesoft.openmaple.Engine.<init>(Unknown Source)
at test.main(test.java:23)`
You likely need to ensure that Eclipse points to externalcall.jar, jopenmaple.dll, and Maple.jar.
First, add
C:\Program Files\Maple 15\java\externalcall.jar
C:\Program Files\Maple 15\java\Maple.jar
by right-clicking the project (I called mine OpenMaple), and going to Build Path > Add External Archives.
Second, create a sub-folder of the package called, say, DLLs, and copy the following file to this folder:
C:\Program Files\Maple 15\bin.X86_64_WINDOWS\jopenmaple.dll
Then, navigate to
Properties > Java Build Path > Source > OpenMaple/src > Native library location
and add OpenMaple/DLLs.

How to specify the correct DLL for SWT when running main?

I'm getting an error where my maven build works fine (using mvn install: the produced executable runs in Windows), but when I try to run main directly from IntelliJ, it is looking for SWT's GTK dlls, which is of course not correct:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-gtk-4528 in java.library.path
no swt-gtk in java.library.path
Can't load library: C:\Users\brandon\.swt\lib\win32\x86_64\swt-gtk-4528.dll
Can't load library: C:\Users\brandon\.swt\lib\win32\x86_64\swt-gtk.dll
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
at org.eclipse.swt.internal.Converter.wcsToMbcs(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at edu.cornell.ansci.dairy.econ.ui.MainWindow$.main(MainWindow.scala:175)
at edu.cornell.ansci.dairy.econ.ui.MainWindow.main(MainWindow.scala)
In fact the actual file contents of the directory look correct, but this is not what is being looked for:
brandon#DESKTOP-MU8LD7O:/mnt/c/Users/brandon/.swt/lib/win32/x86_64$ ls
swt-gdip-win32-4528.dll swt-win32-4528.dll
Here is an image of the run configuration in Intellij (Default JDK is Zulu - maybe I should try to install another?):

UnsatisfiedLinkError in packaged .jar

I've got a program that's packaged as a .jar I need to run for school. In essence the program acts as an interface between a user and a DC motor to control speed, angle, etc.
This program (which required MS C++ to install) runs well on everyone's machines running win7 or 8, but not on my XP_x64 machine. When opened from the start menu, it spawns multiple javaw.exe processes, but no application is created. Run from command line, I find this:
C:\Program Files\Quanser\QICii_USB\bin>java -jar usbQICii.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: C
:\Program Files\Quanser\QICii_USB\bin\lib\usbQICii_jni.dll
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.quanser.raskin.QIC_USB.<clinit>(Unknown Source)
at com.quanser.conduit.pic.PICSource.<init>(Unknown Source)
at com.quanser.raskin.RaskinFrame.<init>(Unknown Source)
at com.quanser.raskin.Raskin.<init>(Unknown Source)
at com.quanser.raskin.Raskin.main(Unknown Source)
I've so far been unable to locate the requested .dll on my system. Two primary questions: is there something obvious I've missed? If I could find the .dll on someone else' machine (so far a no-go) could I grab it and use it on mine (x64 compatibility pending, of course).
Check where usbQICii_jni.dll is located.
My guess is that it is in
"C:\Program Files\Quanser\QICii_USB\lib"
If I'm right, go one directory up, and form
"C:\Program Files\Quanser\QICii_USB"
execute
"java -jar bin\usbQICii.jar"

My java game runs in eclipse, but once exported it "can't find LWJGL" and won't run

I made a Java game in eclipse and when I run the executable .jar it starts up, and the loading screen starts, but then it stops and hangs. I ran it using the command line: "Java -jar filename.jar" and when the loading screen stops it displays an error. This is what the cmd shows:
E:\>Java -jar Speedrunner.jar
60Ticks, FPS:1447
60Ticks, FPS:1627
60Ticks, FPS:1380
Wed Mar 19 12:02:27 GMT 2014 INFO:Initialising sounds..
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: no lwjgl 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 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.openal.AL.<clinit>(AL.java:59)
at org.newdawn.slick.openal.SoundStore$1.run(SoundStore.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at org.newdawn.slick.openal.SoundStore.init(SoundStore.java:292)
at org.newdawn.slick.Sound.<init>(Sound.java:83)
at com.daves.first_Scroller.utils.AudioPlayer.addSound(AudioPlayer.java:29)
at com.daves.first_Scroller.utils.ResourceLoader.loadSounds(ResourceLoader.java:35)
at com.daves.first_Scroller.Game.load(Game.java:110)
at com.daves.first_Scroller.Game.tick(Game.java:160)
at com.daves.first_Scroller.Game.run(Game.java:228)
at java.lang.Thread.run(Unknown Source)
This is saying that LWJGL isn't in java.library.path I've gone to my game in the workspace and configured the build path to include all the libraries and to include them in the .jar when I export my game but I'm still getting the same problem. Does anyone know what I need to do to get this to work? (I looked in the .jar and LWJGL is there in the org file)
Export lwjgl library in your jar.
To do this, right click on the project, properties, java build path, order & export, check your library
Set the (native) library path in the command line:
Java -Djava.library.path=path/to/dir -jar filename.jar
Where dir:
[...] should contain the native part (*.dll files on windows, *.so on linux,
*.jnilib on mac, etc)
(Source)
You need to do two things: you need to include the LWJGL classes on your classpath (or in your jar), and you need to include the natives in your library path.
Exporting from eclipse doesn't automatically include your library path, which is why you're getting your error.
A utility like JarSplice or SvgExe can help with both of these things.

Lauch Eclipse SWT window application from command line error

First off. I am a newbie and green with respect to Java programming.
I created a Java Eclipse "SWT" "Application Window" on a Eclipse Kepler 4.3.1 (32-bit) running WindowBuilder and SWT (swt.jar). The design view is a composite.
The java application runs fine from Eclipse. I simply press the play button and presto.
Problem:
Issuing
java -cp . PkgNetAccelerator32.netAcceleratorApp
yields the following error message:
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Composite
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
at java.lang.Class.getMethod0(Unknown Source)
at java.lang.Class.getMethod(Unknown Source)
at sun.launcher.LauncherHelper.getMainMethod(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.eclipse.swt.widgets.Composite
at java.net.URLClassLoader$1.run(Unknown Source)
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)
... 6 more
I was doing some research and several posts on other issues suggested that the cure is to create a manifest. I saw an article that said something like:
Select the src folder, right click and select export, then Java, then JAR file, specify Manifest.jar and a path on the folder, make sure the "Generate the manifest file" is selected, and press finish.
I created the manifest file and tried launching it with the following command line:
java -jar ../Manifest.jar -cp . PkgNetAccelerator32.netAcceleratorApp
That yielded the same error message above.
I saw another article that said that one should add in the swt.jar file, but that is taken care of by the manifest. No? Specifying "swt.jar" instead of the manifest that I created resulted in an error message:
no main manifest attribute, in ../swt.jar
That error message makes sense.
I am at a loss. How do I run the java application?
I am testing on my Windows 7 Professional 64-bit desktop, but I need to run on CENTOS too. That should be no problem, as I assume whatever the fix on Windows is, will work on CENTOS.
UPDATE:
I placed the two lib files in a /lib folder to match the answer given. I then issued the following command line and got the following error message.
C:\SoftDev\Projects\NetAccelerator\JavaWorkspace\NetAccelerator32>java -cp "bin/*;lib/*" PkgNetAccelerator32.netAcceleratorApp
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot load 32-bit SWT libraries on 64-bit JVM
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.Library.loadLibrary(Unknown Source)
at org.eclipse.swt.internal.C.<clinit>(Unknown Source)
at org.eclipse.swt.widgets.Display.<clinit>(Unknown Source)
at PkgNetAccelerator32.netAcceleratorApp.open(netAcceleratorApp.java:43)
at PkgNetAccelerator32.netAcceleratorApp.main(netAcceleratorApp.java:33)
I found the following article, which produces a command line that works, just that is not reasonable for sending. I much rather use the answer.
Lets assume you have a eclipse project structure similar to this:
Workspace
-> Project
-> src (source code directory)
-> bin (compiled byte code directory as JAR)
-> lib (jar directory)
-> .classpath (eclipse file)
-> .project (eclipse file)
I am assuming that you are exporting the JAR as an executable JAR.
So in order to run a class in that exported JAR with another JAR from the lib directory (swt.jar) while your working directory is the Project directory you will need to execute:
java -cp "bin/*:lib/*" PkgNetAccelerator32.netAcceleratorApp
Using wildcards requires Java 6 or later
Please note: CENTOS requires : as a path separator. Windows uses a semi-colon.
This will add your classes and the swt classes onto the classpath and run your main class PkgNetAccelerator32.netAcceleratorApp
SWT 32bit vs 64bit
You will either need to use a 32bit JVM locally or continue to use a 64bit JVM and use the 64bit version of swt; see swt on windows 64 bit. I would suggest you match your version of your local JVM (32bit or 64bit) with the version that you will be running on the CENTOS machine. You will however need a different swt jar for CENTOS.

Categories

Resources