1

I'm trying to create and swt app which can run on both windows and mac. I'm fairly new to java so have been researching the options to build a runnable jar for both windows and mac (with different dependencies)

So basically there is one main class and the only difference is that one app uses the swt org.eclipse.swt.win32.win32.x86_64 dependency and the other one the org.eclipse.swt.cocoa.macosx.x86_64 dependency.

I currently have the following maven assembly setting:

<build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.1</version>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.connectingmedia.swttest.App</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                
                <executions>
                    <execution>
                        <id>make-assembly</id> <!-- this is used for inheritance merges -->
                        <phase>package</phase> <!-- bind to the packaging phase -->
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

And my dependencies:

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.swt</groupId>
        <artifactId>org.eclipse.swt.win32.win32.x86_64</artifactId>
        <version>4.3</version>
    </dependency>
</dependencies>

Now this works fine to create a windows executable jar. And I can change the dependency to the mac version of swt for the mac version of the jar. But It would be nice to create both at the same time. I found this questions for creating multiple runnable jars: Creating Two Executable Jars Using maven-assembly-plugin

But they use another main class and not different dependencies. <descriptorRef>jar-with-dependencies</descriptorRef> seems to always include all dependencies, or is there a way to select which one to use?

Anyway, The main question is: Am I going the right way to create a maven file that creates multiple runnable jars with different dependencies?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Merijndk
  • 1,674
  • 3
  • 18
  • 35

0 Answers0