使用Maven构建多个架构SWT应用程序 [英] Build multiple architecture SWT application with Maven

查看:590
本文介绍了使用Maven构建多个架构SWT应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为SWT应用程序设置了一个Maven项目。该应用程序运行在几个平台(OS X,Windows 64位,Windows 32位,Linux 64位和Linux 32位),我已经设置好了,以便在运行Maven并打包时检测到该平台应用程序进入不同的目标目录。以下是pom.xml中的相关部分:

 < profiles> 
<个人资料>
< id> linux_x86_64< / id>
< activate>
< os>
< name> linux< / name>
< arch> amd64< / arch>
< / os>
< / activation>
< build>
< directory> $ {project.basedir} / target / $ {project.version} / linux_x86_64< / directory>
< / build>
< / profile>

<个人资料>
< id> win32_x86_64< / id>
< activate>
< os>
< name> linux< / name>
< arch> i386< / arch>
< / os>
< / activation>
< build>
< directory> $ {project.basedir} / target / $ {project.version} / win32_x86_64< / directory>
< / build>
< / profile>
...
< / profiles>

用于SWT的依赖是这样的:

 <依赖性> 
<依赖关系>
< groupId> org.eclipse< / groupId>
< artifactId> swt< / artifactId>
< version> 3.7.2.v3740< / version>
< / dependency>
...
< / dependencies>为了使事情清晰,我已经在本地存储库中安装了SWT虚拟包(org.eclipse)。 swt_3.7.2.v3740f.jar)和所有平台特定的(org.eclipse.swt.gtk.linux.x86_64_3.7.2.v3740f,org.eclipse.swt.win32.x86_64_3.7.2 .v3740f等)。



我的包依赖关系的方式是使用一个lib文件夹使用maven依赖插件,而Maven很聪明,可以复制SWT虚拟包以及我正在打包应用程序的平台特定的机器之一。到目前为止这么好...



问题是我想从单个机器编译不同平台的应用程序。我如何实现这一点?



我已经尝试在每个配置文件中设置每个平台所需的SWT jar的属性,就像这样(Windows 64位的示例):

 < properties> 
< swt.artifactId> swt.win32.x86_64< /swt.artifactId>
< swt.version> 3.7.2< /swt.version>
< / properties>

但是,采用这种方法,配置文件特定的SWT jar和平台特定的一个我正在运行的Maven被复制到lib目录,最后是三个jar:




  • swt-3.7。 2.v3740.jar

  • swt.gtk.linux.x86_64-3.7.2.jar

  • swt.win32.x86_64-3.7.2。 jar



有没有一种方法可以指定一个配置文件,忽略运行它的机器,这样我就不会需要手动删除其SWT jar?



提前感谢

解决方案

p>不知道depency-plugin如何处理它,但是如果你只有一个依赖关系,它应该可以工作:

  <依赖性> 
< groupId> $ {swt.groupId}< / groupId>
< artifactId> $ {swt.artifactId}< / artifactId>
< version> 3.7.2< / version>
< scope> compile< / scope>
< / dependency>

然后,这些配置文件如下:

 <型材> 
< id> gtk_linux_x86_64< / id>
< activate>
< os>
< name> linux< / name>
< arch> x86_64< / arch>
< / os>
< / activation>
<属性>
< swt.groupId> org.eclipse.swt.gtk.linux< /swt.groupId>
< swt.artifactId> x86_64< /swt.artifactId>
< / properties>
< / profile>

现在,所需的SWT版本被自动使用,但可以设置为您需要的(例如建立一个版本)以及使用:



mvn -P gtk_linux_x86_64



注意:根据需要更改您的groupId和artifactId。


I've set up a Maven project for a SWT application. This application runs on several platforms (OS X, Windows 64-bit, Windows 32-bit, Linux 64-bit and Linux 32-bit) and I've set it up so that the platform is detected when Maven is run and the packaged application goes to different destination directories. Here are the relevant parts from pom.xml to achieve this:

<profiles>
  <profile>
    <id>linux_x86_64</id>
    <activation>
      <os>
        <name>linux</name>
        <arch>amd64</arch>
      </os>
    </activation>
    <build>
      <directory>${project.basedir}/target/${project.version}/linux_x86_64</directory>
    </build>
  </profile>

  <profile>
    <id>win32_x86_64</id>
    <activation>
      <os>
        <name>linux</name>
        <arch>i386</arch>
      </os>
    </activation>
    <build>
      <directory>${project.basedir}/target/${project.version}/win32_x86_64</directory>
    </build>
    </profile>
  ...
</profiles>

And the dependency used for SWT is this:

<dependencies>
  <dependency>
    <groupId>org.eclipse</groupId>
    <artifactId>swt</artifactId>
    <version>3.7.2.v3740</version>
  </dependency>
...
</dependencies>

To make things clear, I have installed in my local repository the SWT dummy package (org.eclipse.swt_3.7.2.v3740f.jar) and all the platform-specific ones (org.eclipse.swt.gtk.linux.x86_64_3.7.2.v3740f, org.eclipse.swt.win32.x86_64_3.7.2.v3740f, etc.).

The way I pack dependencies is with a "lib" folder using the maven-dependency-plugin and Maven is smart enough to copy both the SWT dummy package and the platform-specific one of the machine where I'm packaging the application. So far so good...

The problem is that I would like to compile the application for the different platforms from a single machine. How would I achieve this?

I've tried setting up a property in each profile with the SWT jar needed for each platform, like this (example for Windows 64-bit):

<properties>
  <swt.artifactId>swt.win32.x86_64</swt.artifactId>
  <swt.version>3.7.2</swt.version>
</properties>

But taking this approach both the profile-specific SWT jar and the platform-specific one where I'm running Maven get copied into the "lib" directory, ending up with three jars:

  • swt-3.7.2.v3740.jar
  • swt.gtk.linux.x86_64-3.7.2.jar
  • swt.win32.x86_64-3.7.2.jar

Is there a way in which I could specify a profile ignoring the machine where I'm running it so that I don't need to manually remove its SWT jar?

Thanks in advance.

解决方案

Not sure how the depency-plugin handles it, but it should work if you have only one dependency like this one:

    <dependency>
        <groupId>${swt.groupId}</groupId>
        <artifactId>${swt.artifactId}</artifactId>
        <version>3.7.2</version>
        <scope>compile</scope>
    </dependency>

And then profiles like these:

<profile>
  <id>gtk_linux_x86_64</id>
  <activation>
    <os>
      <name>linux</name>
      <arch>x86_64</arch>
    </os>
  </activation>
  <properties>
    <swt.groupId>org.eclipse.swt.gtk.linux</swt.groupId>
    <swt.artifactId>x86_64</swt.artifactId>
  </properties>
</profile>

Now the needed version of SWT get's used automatically, but can be set to what you need (e.g. when building a release) as well using:

mvn -P gtk_linux_x86_64

Note: Change your groupId and artifactId as needed.

这篇关于使用Maven构建多个架构SWT应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆