I'm an Eclipse newbie and I'm trying to build a mixed AWT/SWT application. Here's my code:
public class HelloWorldSWT {
public static void main(String[] args) {
Frame frame = new Frame("My AWT Frame"); // java.awt.Frame
frame.setLayout( new BorderLayout() );
Canvas canvas = new Canvas(); // java.awt.Canvas
frame.add(canvas, BorderLayout.CENTER);
frame.setVisible(true);
Display display = new Display(); // display object to manage SWT lifecycle.
Shell swtShell = SWT_AWT.new_Shell(display, canvas);
Button m_button = new Button(swtShell, SWT.PUSH);
m_button.setText( "button" );
// invoke the AWT frame rendering by making the frame visible
// This starts the EDT
frame.setVisible(true);
// standard SWT dispatch loop
while(!swtShell.isDisposed())
{
if(!display.readAndDispatch())
display.sleep();
}
swtShell.dispose();
}
}
This compiles fine, but when I run it as application in Eclipse, I get the following error:
Exception in thread "main"
java.lang.UnsatisfiedLinkError:
sun.awt.SunToolkit.getAppContext(Ljava/lang/Object;)Lsun/awt/AppContext;
at
sun.awt.SunToolkit.getAppContext(Native
Method) at
sun.awt.SunToolkit.targetToAppContext(Unknown
Source) at
sun.awt.windows.WComponentPeer.postEvent(Unknown
Source) at
sun.awt.windows.WComponentPeer.postPaintIfNecessary(Unknown
Source) at
sun.awt.windows.WComponentPeer.handlePaint(Unknown
Source) at
sun.java2d.d3d.D3DScreenUpdateManager.repaintPeerTarget(Unknown
Source) at
sun.java2d.d3d.D3DScreenUpdateManager.createScreenSurface(Unknown
Source) at
sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown
Source) at
sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown
Source) at
sun.awt.windows.WComponentPeer.setBounds(Unknown
Source) at
sun.awt.windows.WWindowPeer.setBounds(Unknown
Source) at
sun.awt.windows.WComponentPeer.initialize(Unknown
Source) at
sun.awt.windows.WCanvasPeer.initialize(Unknown
Source) at
sun.awt.windows.WPanelPeer.initialize(Unknown
Source) at
sun.awt.windows.WWindowPeer.initialize(Unknown
Source) at
sun.awt.windows.WFramePeer.initialize(Unknown
Source) at
sun.awt.windows.WComponentPeer.(Unknown
Source) at
sun.awt.windows.WCanvasPeer.(Unknown
Source) at
sun.awt.windows.WPanelPeer.(Unknown
Source) at
sun.awt.windows.WWindowPeer.(Unknown
Source) at
sun.awt.windows.WFramePeer.(Unknown
Source) at
sun.awt.windows.WToolkit.createFrame(Unknown
Source) at
java.awt.Frame.addNotify(Unknown
Source) at
java.awt.Window.show(Unknown Source)
at java.awt.Component.show(Unknown
Source) at
java.awt.Component.setVisible(Unknown
Source) at
java.awt.Window.setVisible(Unknown
Source) at
HelloWorldSWT.main(HelloWorldSWT.java:20)
What am I doing wrong?
Since version 3.3, SWT automatically finds its required platform-specific libraries, which are inside the swt.jar (at the top level of the JAR contents). So all you need is swt.jar in the classpath, and it works.
One way to get an UnsatisifiedLinkError is if you're using a swt.jar for another platform -- they're all named "swt.jar"; for example, if you download the one for Linux, and try to use it on Windows. The project will compile OK since all the API-level code is the same Java for every platform, but it will fail when you run because the native libraries are wrong.
However, since the error in this case happens in AWT, it might be something else, not directly related to SWT. First, make sure you've downloaded the Windows SWT release. When you import it into your workspace, it creates an Eclipse project named org.eclipse.swt, which contains the swt.jar. You then make org.eclipse.swt a required project for your project, and nothing else in the Build Path besides a valid, clean JRE (you can try defining a new one [Window -> Preferences -> Java -> Installed JREs], or just use a different one you might have installed).
You can also test it from the shell/command window. Go to your project directory. The command should be as simple as:
java -cp bin;..\org.eclipse.swt\swt.jar HelloWorldSWT
I got your code to run (Vista-32, JDK 6_15), but the window opened really small, and would not close. I don't know anything about the SWT-AWT bridge though, so good luck with that....
The UnsatisfiedLinkError is indicating that a native library that you are relying upon is not found when you are trying to run your app. If you are compiling this in your IDE, then the library is in your build path. If you are running this from with your IDE and getting this error, the libray is not in your Run path. Check your Run Dialog to see that the libraries you have in your build path are in your run path.
As mentioned, this indicates that the JVM cannot find a native library. Since you're mixing AWT/SWT I assume that the JVM can't find the SWT libraries (.dll for windows, .so for linux, not sure for mac). I'm partial to using an system property to tell java where to look.
-Djava.library.path=<absolute path to the .dll/.so that SWT needs>
I have had exactly the same problem, and could only get it resolved by completely removing and re-installing Java. It seems that somehow, one of the DLLs, containing the native AWT methods, had managed to get screwed up.
I have had solved this problem,
I search this information for a long time,but i can't find one to solve my problem,
after i check my java version
i found that jdk and jre version is different,
for example
i found that one extra document on my file system
jdk 1.4 jre 1.4 jre 1.5(extra)
you should delete the new version of the jre(jre1.5)
then ok,my english is poor,i hope my message will do a favour,
if you have some question ,you can connect to me,email:fish2-2#163.com
Related
Why it seems that is impossible to load a library (.dll) in Java, if it is not located in /jre/bin folder. It's crazy, but I have 2 dll's:
aa.dll
bb.dll, which depends on aa.dll
If I copy these dll's in C:\Tmp the following code it is not working.....
If copy these dll'd in C:\Program Files\Java\jre1.8.0_25\bin, the same code it's working.
The code, very simple:
public class Main {
public static void main(String[] args) {
System.load("C:\\Tmp\\ftd2xx.dll");
System.out.println("ftd2xx.dll loaded");
System.load("C:\\Tmp\\JD2XX.dll");
}
}
The error (result):
ftd2xx.dll loaded
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jd2xx 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 jd2xx.JD2XX.<clinit>(JD2XX.java:729)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at Main_02.main(Main_02.java:7)
To be more confusing, one library I can load from c:\Tmp (aa.dll), the other one I cannot (bb.dll).
This last one requires to reside in C:\Program Files\Java\jre1.8.0_25\bin.
If somebody has any useful idea, I will appreciate very much.
I tought the JVM does not want to load possible dangerous, or untrusted native code? And if it resides in the jre folder it consider the code is safe? But it is jus an ideea.
Thank you.
I confirm the same:
Windows 7(64bit);jre1.8.0_102(32bit);DLL's(32bit);
Exactly the same but in my case one dll(aa.dll) is dependent on another bb.dll (aa.dll->bb.dll)
aa.dll can be loaded from anywhere (a projects lib path for ex), but only and only if I copy bb.dll to jre1.8.0_102\bin directory; No chances to load otherwise. Tried various combinations to set -Djava.library.path=project_path\lib, to set system PATH=project_path\lib, copy both dll's to windows\system32 - nothing helps, the only chance is to have it on jre\bin path.
AN UPDATE:
And you have answered your question your self. It's a security:
Go to -> Java Control Panel -> Advanced -> Mixed code ..
Set "Disable verification.."
and aa.dll loads successfully. Both stored in project_path\lib
I'm taking over this guy application and he left me pretty much nothing, even the coding is not commented. With luck (and a bit of time), I was able to improve the app and make it run like a charm on my computer.
But I'm having a problem, which is annoying and prevent me from upgrading the app. My app can run fine on any machines installed with java version 1.7.0_21, but when I update to newer version (for now it's 1.7.0_60), the app can not run, it just keeps having this stupid error and I can not do anything to fix it.
Here is the error log:
RenderJob.run: internal exception
java.lang.UnsatisfiedLinkError: com.sun.prism.d3d.D3DContext.nSetBlendEnabled(JZ
Z)I
at com.sun.prism.d3d.D3DContext.nSetBlendEnabled(Native Method)
at com.sun.prism.d3d.D3DContext.initState(D3DContext.java:84)
at com.sun.prism.d3d.D3DResourceFactory.<init>(D3DResourceFactory.java:5
7)
at com.sun.prism.d3d.D3DPipeline.createResourceFactory(D3DPipeline.java:
150)
at com.sun.prism.d3d.D3DPipeline.getD3DResourceFactory(D3DPipeline.java:
156)
at com.sun.prism.d3d.D3DPipeline.findDefaultResourceFactory(D3DPipeline.
java:182)
at com.sun.prism.d3d.D3DPipeline.getDefaultResourceFactory(D3DPipeline.j
ava:204)
at com.sun.prism.GraphicsPipeline.getDefaultResourceFactory(GraphicsPipe
line.java:97)
at com.sun.javafx.tk.quantum.QuantumRenderer$3.run(QuantumRenderer.java:
143)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
at com.sun.prism.render.RenderJob.run(RenderJob.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumRenderer$PipelineRunnable.run(Quantu
mRenderer.java:98)
at java.lang.Thread.run(Unknown Source)
I found another issue which is similar
Unable to deploy JavaFX applicaiton with external libraries in a JAR
but I can not apply that in my case since this program/framework need to run from a .bat file (which is command line actually) to creat a bunch of report files and folders.
Wich JavaFX version you have attached to your app?
I suspect the attached JavaFX version is not compatible with 1.7.0_60. I had some equal issues with that.
But the exception is new to me (its some internal prism stuff)
It has been my experience that the JFXRT jar is tightly coupled to the JRE/JDK version.update that it comes bundled with (in the case of oracles jvm). This means that the application needs to be ran on a jvm version.update as it was pulled from. You should be able to work around this by using the prescribed methods of building found here, http://docs.oracle.com/javafx/2/deployment/packaging.htm.
I am trying to get tess4j working in a simple test application to perform OCR on a pdf file but receive the following error and cannot fathom out how to resolve it:
Exception in thread "main" java.lang.RuntimeException: Unable to load library 'gs': dlopen(libgs.dylib, 9): image not found
Please download, install GPL Ghostscript from http://sourceforge.net/projects/ghostscript/files and/or set the appropriate environment variable.
at net.sourceforge.vietocr.PdfUtilities.convertPdf2Tiff(Unknown Source)
at net.sourceforge.vietocr.ImageIOHelper.getIIOImageList(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at Test.main(Test.java:11)
I have got eclipse to print out my path file as it sees it and it contains /usr/loca/bin/gs (checked as correct with which gs) as needed and I can happily run gs from the terminal. Any ideas on how to get this working?
The code is shown in the image at https://dl.dropboxusercontent.com/u/61920208/Screen%20Shot%202013-09-02%20at%2013.44.24.png
Thanks in advance for any help
As per the suggestion, reinstalling ghostsrcipt (via ports rather than the dmg)sorted this out for me.
In my project I want to capture image from my webcam.
I configured step by step following the instructions from this "OpenCV-JavaCV : eclipse project configuration windows 7" blog post.
After configuration is finished, i tested samples codes and the application found my webcam
SETUP: Setting up device 0
SETUP: Namuga 1.3M Webcam
SETUP: Couldn't find preview pin using SmartTee
SETUP: Capture callback set
SETUP: Device is setup and ready to capture.
and then i got an error which is .dll error.
I use windows 7 x64.
Exception in thread "Thread-2" java.lang.UnsatisfiedLinkError: C:\Users\Administrator\AppData\Local\Temp\javacpp153028723186\jniopencv_core.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary1(Unknown Source)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.googlecode.javacpp.Loader.loadLibrary(Loader.java:418)
at com.googlecode.javacpp.Loader.load(Loader.java:368)
at com.googlecode.javacpp.Loader.load(Loader.java:315)
at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:131)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.googlecode.javacpp.Loader.load(Loader.java:334)
at com.googlecode.javacpp.Loader.load(Loader.java:315)
at com.googlecode.javacv.cpp.opencv_core$CvArr.<clinit>(opencv_core.java:158)
at com.googlecode.javacv.VideoInputFrameGrabber.grab(VideoInputFrameGrabber.java:158)
at GrabberShow.run(GrabberShow.java:24)
at java.lang.Thread.run(Unknown Source)
How can i solve this problem?
Check whether your Opencv version and JavaCv versions are matching each other. You can check that on the readme file on javacv-bin it specifically say about the required version of the opencv.
Unsatisfied link means that not all native code libraries required by jniopencv_core.dll could be found.
Did you deploy them all or just jniopencv_core.dll?
I faced this problem on Windows XP and Windows 7, and this is how I fixed it on both platforms, using Netbeans 7.2:
Install all required software:
FFmpeg (32-bit shared): Zeranoe FFmpeg offers win32 builds. Download and extract ffmpeg-20121020-git-04bf2e7-win32-shared.7z. Place its content at C:\ffmpeg.
Note: make sure C:\ffmpeg\bin is a valid path.
OpenCV 2.4.2 (32-bit): download OpenCV-2.4.2.exe and extract it. Place its content at C:\opencv.
Note: make sure C:\opencv\build\x86\vc10\bin is valid path.
JavaCV 0.2: download javacv-0.2-bin.zip and extract it. Move the extracted folder to C:\javacv-bin.
Microsoft Visual C++ redistributable package (32-bit): download and install vcredist_x86.exe.
Configure the environment:
Edit the environment variable PATH and append the following paths at the end:
C:\ffmpeg\bin;C:\opencv\build\x86\vc10\bin
Now you ready to create a new Netbeans project and test your application. But before you compile it,dDon't forget to right-click the Libraries folder at the pProjects window* and click Add Jar/FOLDER to select all the .jar files located at C:\javacv-bin.
Make sure you have the vm arg -Djava.library.path=<path-to-native> that points to the directory with your dlls.
I need to run a Java application, which we are trying to port to Java 6, on an NT box.
I manage to run java 5 on it (although not officially supported), but when I try to run java 6 I get the following error:
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files\Java\jre1.6.0_05\bin\awt.dll: The specified procedure could not be found
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at sun.security.action.LoadLibraryAction.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.NativeLibLoader.loadLibraries(Unknown Source)
at sun.awt.DebugHelper.<clinit>(Unknown Source)
at java.awt.EventQueue.<clinit>(Unknown Source)
at javax.swing.SwingUtilities.invokeLater(Unknown Source)
at ui.sequencer.test.WindowTest.main(WindowTest.java:136)
Anybody has any idea how to solve this?
This persists even when I move the java executables to another directory with no spaces in its name.
p.s.
I know, I should upgrade, but it's not up to me or my company - this is a very very bug huge gigantic company we work with, and they intend to keep NT for another 5 years.
OK, Thanks for all the viewers and to #Roel Spiker and #Partyzant for their answers.
It can't be done. Not unless you install windows2000 on the NT box. This is because awt.dll fr J6SE uses new methods in User32.dll, which is part of the windows OS (linked to kernel.dll et al). Use the dll dependency walker and see for yourself.
Another possible solution is to alter OpenJDK slightly to use other methods available in windows NT.
Java SE 6 requires at least Windows 2000.
I you are not using a GUI, for instance AWT, Swing or SWT, you could try starting you application in headless mode. See http://java.sun.com/developer/technicalArticles/J2SE/Desktop/headless/ for more information. To start java in headless mode, use java -Djava.awt.headless=true
It would take care of the UnsatisfiedLinkError. I don't know if that's the only obstacle though.