Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swt libraries cannot be resolved

Tags:

maven

swt

I am using below maven dependency to develop swt application.

<dependency>
  <groupId>org.eclipse.platform</groupId>
  <artifactId>org.eclipse.swt</artifactId>
  <version>3.108.0</version>
</dependency>

But when I tried to import below packages,

import org.eclipse.swt.*;
import org.eclipse.swt.widgets.*;

I am getting the error like "The import org.eclipse cannot be resolved"

What is the right maven dependency to work with swt Desktop application?

like image 934
Hari Krishna Avatar asked Oct 10 '18 14:10

Hari Krishna


2 Answers

If you need to solve the SWT dependencies with Maven for Windows, Linux and Mac you could use a technique described by Olivier Cailloux here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=520337#c0:

The main problem is the dependency of the platform specific builds (for example, org.eclipse.swt.gtk.linux.x86_64) to some generic build (org.eclipse.swt), which in turn depends on platform specific builds [...]

I believe the strategy suggested at https://github.com/oliviercailloux/java-course/tree/master/SWT#maven, namely, excluding org.eclipse.platform:org.eclipse.swt, is better than those suggested in bug 510186 comment 12. Excluding org.eclipse.platform:org.eclipse.swt conveys the intent better (this dependency is not useful and triggers some problems, so let’s tell Maven that we don’t really need it)

Basically you need to set the corresponding Maven profile for the correct OS and insert this in your pom:

<profiles>
   <profile>
      <id>swt-unix</id>
      <activation>
         <os>
            <family>unix</family>
         </os>
      </activation>
      <properties>
         <swt.artifactId>org.eclipse.swt.gtk.linux.x86_64</swt.artifactId>
         <env>linux</env>
      </properties>
      <dependencies>
         <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>${swt.artifactId}</artifactId>
            <version>3.108.0</version>
            <optional>true</optional>
            <exclusions>
               <exclusion>
                  <groupId>org.eclipse.platform</groupId>
                  <artifactId>org.eclipse.swt</artifactId>
               </exclusion>
            </exclusions>
         </dependency>
      </dependencies>
   </profile>
   <profile>
      <id>swt-mac</id>
      <activation>
         <os>
            <family>mac</family>
         </os>
      </activation>
      <properties>
         <swt.artifactId>org.eclipse.swt.cocoa.macosx.x86_64</swt.artifactId>
         <env>mac</env>
      </properties>
      <dependencies>
         <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>${swt.artifactId}</artifactId>
            <version>3.108.0</version>
            <optional>true</optional>
            <exclusions>
               <exclusion>
                  <groupId>org.eclipse.platform</groupId>
                  <artifactId>org.eclipse.swt</artifactId>
               </exclusion>
            </exclusions>
         </dependency>
      </dependencies>
   </profile>
   <profile>
      <id>swt-windows</id>
      <activation>
         <os>
            <family>windows</family>
         </os>
      </activation>
      <properties>
         <swt.artifactId>org.eclipse.swt.win32.win32.x86_64</swt.artifactId>
         <env>windows</env>
      </properties>
      <dependencies>
         <dependency>
            <groupId>org.eclipse.platform</groupId>
            <artifactId>${swt.artifactId}</artifactId>
            <version>3.108.0</version>
            <optional>true</optional>
            <exclusions>
               <exclusion>
                  <groupId>org.eclipse.platform</groupId>
                  <artifactId>org.eclipse.swt</artifactId>
               </exclusion>
            </exclusions>
         </dependency>
      </dependencies>
   </profile>
</profiles>
like image 86
Loris Securo Avatar answered Oct 11 '22 03:10

Loris Securo


You haven't specified which repository you're trying to pull from, but SWT is not available from Maven Central. The simplest method that I know is to use https://github.com/maven-eclipse/maven-eclipse.github.io.

You can add the repository:

<repositories>
    <repository>
        <id>maven-eclipse-repo</id>
        <url>http://maven-eclipse.github.io/maven</url>
    </repository>
</repositories>

And then the platform-specific dependency that you need to support. For example:

<dependency>
    <groupId>org.eclipse.swt</groupId>
    <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
    <version>${swt.version}</version>
</dependency>
like image 40
avojak Avatar answered Oct 11 '22 02:10

avojak