创建跨平台 Java SWT 应用程序 [英] Create cross platform Java SWT Application

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

问题描述

我使用 SWT 编写了一个 Java GUI.我使用 ANT 脚本(下面的片段)打包应用程序.

I have written a Java GUI using SWT. I package the application using an ANT script (fragment below).

<jar destfile="./build/jars/swtgui.jar" filesetmanifest="mergewithoutmain">
  <manifest>
    <attribute name="Main-Class" value="org.swtgui.MainGui" />
    <attribute name="Class-Path" value="." />
  </manifest>
  <fileset dir="./build/classes" includes="**/*.class" />
  <zipfileset excludes="META-INF/*.SF" src="lib/org.eclipse.swt.win32.win32.x86_3.5.2.v3557f.jar" />
</jar>

这会生成一个 jar,在 Windows 上我只需双击即可运行我的 GUI.缺点是我必须明确地将 windows SWT 包打包到我的 jar 中.

This produces a single jar which on Windows I can just double click to run my GUI. The downside is that I have had to explicitly package the windows SWT package into my jar.

我希望能够在其他平台(主要是 Linux 和 OS X)上运行我的应用程序.最简单的方法是创建特定于平台的 jar,将适当的 SWT 文件打包到单独的 JAR 中.

I would like to be able to run my application on other platforms (primarily Linux and OS X). The simplest way to do it would be to create platform specific jars which packaged the appropriate SWT files into separate JARs.

有没有更好的方法来做到这一点?是否可以创建一个可以在多个平台上运行的 JAR?

Is there a better way to do this? Is it possible to create a single JAR which would run on multiple platforms?

推荐答案

我有一个工作实现,现在引用自 SWT 常见问题.

I have a working implementation which is now referenced from the SWT FAQ.

此方法现在可用作 ANT 任务:SWTJar

This approach is now available to use as an ANT task: SWTJar

SWTJar 现在已更新为使用 Alexey Romanov 的解决方案,如上所述.

SWTJar has now been updated to use Alexey Romanov's solution as described above.

build.xml

首先,我构建了一个包含所有应用程序类的 jar.

First I build a jar containing all of my application classes.

<!-- UI (Stage 1) -->   
<jarjar jarfile="./build/tmp/intrace-ui-wrapper.jar">
  <fileset dir="./build/classes" includes="**/shared/*.class" />
  <fileset dir="./build/classes" includes="**/client/gui/**/*.class" />
  <zipfileset excludes="META-INF/*.MF" src="lib/miglayout-3.7.3.1-swt.jar"/>
</jarjar>

接下来,我构建了一个 jar 来包含以下所有内容:

Next, I build a jar to contain all of the following:

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