Pixel
Pixel

Reputation: 394

Resurrect old Java project with SWT and Maven

I am trying to resurrect some old code from the Java 1.5 era. Maven (which I am not super familiar with) is the build tool, probably an older major version. The old code also uses SWT, which I am also not super familiar with.

I would like to update and get it to compile as 1.8 code. I have changed the MANIFEST.MF to have Bundle-RequiredExecutionEnvironment: JavaSE-1.8, and changed the pom.xml to have 1.8 for <source> and <target>.

When I run maven to build, it looks like a disaster. The relevant lines appear to be:

[WARNING] The POM for swt:org.eclipse.jface_3.2.0:jar:R is missing, no dependency information available
[WARNING] The POM for swt:org.eclipse.swt.win32.win32.x86_3.2.0:jar:R is missing, no dependency information available
[WARNING] The POM for swt:org.eclipse.swt_3.2.0:jar:R is missing, no dependency information available
[WARNING] The POM for swt:org.eclipse.core.commands_3.2.0:jar:R is missing, no dependency information available
[...]
[ERROR] Failed to execute goal on project MyProject: Could not resolve dependencies for project MyGroupId:MyArtifactId:jar:0.01: The following artifacts could not be resolved: swt:org.eclipse.jface_3.2.0:jar:R, swt:org.eclipse.swt.win32.win32.x86_3.2.0:jar:R, swt:org.eclipse.swt_3.2.0:jar:R, swt:org.eclipse.core.commands_3.2.0:jar:R: Failure to find swt:org.eclipse.jface_3.2.0:jar:R in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced

Here are the relevant dependencies:

        <dependency>
            <groupId>swt</groupId>
            <artifactId>org.eclipse.jface_3.2.0</artifactId>
            <version>R</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>swt</groupId>
            <artifactId>
                org.eclipse.swt.win32.win32.x86_3.2.0
            </artifactId>
            <version>R</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>swt</groupId>
            <artifactId>org.eclipse.swt_3.2.0</artifactId>
            <version>R</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>swt</groupId>
            <artifactId>org.eclipse.core.commands_3.2.0</artifactId>
            <version>R</version>
            <scope>compile</scope>
        </dependency>

It looks like repositories and groupIds and artifactIds have moved around over the years, with many versions no longer available. I have tried to update the dependencies to newer versions, but most versions depend on newer Java versions.

Does a list of active dependencies for SWT that will work under Java 1.8 exist?


Update: Looking through the repository https://repo.eclipse.org/#view-repositories;eclipse~browsestorage and using repository https://repo.eclipse.org/content/groups/releases/

org.eclipse.platform / org.eclipse.jface / 3.12.1 - Java 8
org.eclipse.platform / org.eclipse.core.commands / 3.10.100 - Java 11
org.eclipse.platform / org.eclipse.swt / 3.126.0 & 3.128.0 - Java 17; no class files in JAR; no other versions with actual JAR files
org.eclipse.platform / org.eclipse.swt / 3.127.0 & 3.128.0 - Java 17; no other versions with actual JAR files

I am thinking that the original author of the code had downloaded specific jar files for SWT and manually placed them in his local repository.

Upvotes: 1

Views: 74

Answers (1)

Pixel
Pixel

Reputation: 394

I found a method to get past the problem. This method does not require putting the SWT jar files into the local repository. There are 2 tricks required to get this to work.

  1. As suggested by @greg-449 download the SDK from the Eclipse Archive. Locate and copy the appropriate files. I tried copying Eclipse SDK 4.1.2, and copied these files:
  • org.eclipse.core.commands_3.6.0.I20110111-0800.jar
  • org.eclipse.jface_3.7.0.v20110928-1505.jar
  • org.eclipse.swt.win32.win32.x86_64_3.7.2.v3740f.jar
  • org.eclipse.swt_3.7.2.v3740f.jar

I put these under a lib folder under the top level. There is probably a more elegant place to put them.

  1. Use this StackOverflow answer to hard-code local files in the pom.xml.

In my case, it looked like this:

    <dependency>
        <groupId>org.eclipse.platform</groupId>
        <artifactId>org.eclipse.swt</artifactId>
        <version>3.7.2</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/org.eclipse.swt_3.7.2.v3740f.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.eclipse.platform</groupId>
        <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
        <version>3.7.2</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/org.eclipse.swt.win32.win32.x86_64_3.7.2.v3740f.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.eclipse.platform</groupId>
        <artifactId>org.eclipse.jface</artifactId>
        <version>3.7.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/org.eclipse.jface_3.7.0.v20110928-1505.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>org.eclipse.platform</groupId>
        <artifactId>org.eclipse.core.commands</artifactId>
        <version>3.6.0</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/lib/org.eclipse.core.commands_3.6.0.I20110111-0800.jar</systemPath>
    </dependency>

I do not know if the groupId and artifactId values are correct, but it is good enough to get the old code to compile.

Also there will be some Maven warnings as shown below, but in my case I just want it to compile. You can get change to a different warning by hard-coding the full path instead of using the relative variable.

[WARNING] 'dependencies.dependency.systemPath' for org.eclipse.platform:org.eclipse.swt:jar should not point at files within the project directory, ${project.basedir}/lib/org.eclipse.swt_3.7.2.v3740f.jar will be unresolvable by dependent projects

Upvotes: 0

Related Questions