Environment settings before SWT development

xiaoxiao2021-03-06  17

In order to develop SWT applications, you need to add the SWT library to classpath and set the necessary environment variables.

First, you have to find the Swt.jar library file in the eclipse_home / eclipse / plugins / org.eclipse.swt.win32_2.1.0 / ws / win32 directory. Note that the "org.eclipse.swt.win32_2.1.0" directory here is related to the version of Eclipse. I can't find the file search function. Then open the following window Project-> proties-> javabuildpath-> libraries-> add variable -> eclipse home -> Extend Add the SWT.jar file to the classpath.

Then you will definitely compile this SWT application. However, the operation exception shown below will appear. This abnormality is that the SWT.jar library uses the original branch. You need to set up java.library.path environment variables to use the native libraries in Java.

The output of console is as follows:

java.lang.UnsatisfiedLinkError: no swt-win32-2136 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.eclipse.swt.internal.library.loadLibrary (library.java:108) at Org.eclipse.swt.internal.win32.os. (Os.java: 46) AT Org.eclipse .swt.widgets.display.internal_new_gc (display.java: 1291) at org.eclipse.swt.graphics.device.init (device.java: 547) at Org.eclipse.swt.widgets.display.init (Display.java : 1316) AT org.eclipse.swt.graphics.device. (device.java: 96) at Org.eclipse.swt.widgets.display. (display.java: 291) at Org.eclipse. SWT.WIDGETS.DISPLAY. (Display.java: 287) at com.swtdesigner.trytry.main (Trytry.java: 24) Exception in thread "main"

Press the step below to set the java.library.path variable: Open Run-> Run ...-> Java Applicaton-> "Project" -> arguments -> VM Arguments. Enter in "VM Arguments"

-Djava.library.path = c: /eclipse/plugins/org.eclipse.swt.win32_2.1.0/OS/WIN32/X86

Note To enter the path where your own swt.jar is located.

Tip: Load a native store:

If you need to load your own application, you can use the Runtime.Getplatform.LoadLibrary ("libraryname") method.

Compile your app again, this time it passed.

转载请注明原文地址:https://www.9cbs.com/read-44762.html

New Post(0)