I am looking at how to import the SWT UI library into my Java project. I found the pom file for SWT on maven at: https://repo1.maven.org/maven2/org/eclipse/swt/3.3.0-v3346/swt-3.3.0-v3346.pom
From the file I added the following line to my build.gradle
file
compile "org.eclipse:swt:3.3.0"
however when I added it to my build.gradle
I received the following error:
Project 'L-CAD Main' is missing required library: '/home/ashley/unresolved dependency - org.eclipse swt 3.3.0'
If I understand this right this means it can't find the dependency, so I don't know what I'm doing wrong.
My IDE is Eclipse.
You have to use the whole package name in the dependency line, including the version number.
Therefore add: compile "org.eclipse:swt:3.3.0-v3346"
to the build.gradle
file.
When using jcenter with Gradle for compiling Eclipse SWT.
The Repository that Gradle pulls from for SWT is JCenter SWT.
Edit your gradle.build
accordingly. You need to add the compile line to the dependencies
closure of your Grable.build
. For example, if you want to build for 64 bit Linux use:
compile 'org.eclipse.swt:org.eclipse.swt.gtk.linux.x86_64:4.3'
According to Eclipse Foundation,
SWT is an open source widget toolkit for Java designed to provide efficient, portable access to the user-interface facilities of the operating systems on which it is implemented.
This means that unlike other Java GUI tool kits like Swing, SWT does not provide its own widgets, but allows you to write one Java UI that can use with a platform specific implementation of SWT for the desired OS, like windows or mac.
For you desired Operating System, you will want to select the corresponding library version from JCenter SWT, where the compile line from gradle.build
should reflect:
compile 'org.eclipse.swt:<target platform>:4.3'
Where <target platform>
for example is org.eclipse.swt.cocoa.macosx.x86_64/
or org.eclipse.swt.win32.win32.x86_64/
.
来源:https://stackoverflow.com/questions/36117049/import-swt-as-a-gradle-dependency