SWT罐子不同的平台 [英] SWT jar for different platform

查看:281
本文介绍了SWT罐子不同的平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的<一个href=\"http://djproject.sourceforge.net/ns/documentation/javadoc/chrriis/dj/nativeswing/swtimpl/components/JWebBrowser.html\"相对=nofollow> JWebBrowser 在Swing应用程序。此类属于的DJ项目。它需要SWT的jar执行。现在,我已经包含了窗口的应用程序我的jar包SWT罐子。我想知道我怎么能包括在同一包装的Linux / MAC SWT的罐子?我使用Ant来构建应用程序JAR。我应该建立罐子放在不同的SWT罐子不同的平台呢?

I am using JWebBrowser in a swing application. This class belongs to The DJ Project. It needs swt jar to execute. Now I have included swt jar for windows to my jar packaging of the application. I want to know how can I include swt jars for linux/mac in the same packaging? I am using ant to build the application jar. Should I build the jar putting different swt jar for different platform?

推荐答案

如果你想有在不同平台上运行的一个版本(赢/苹果/ Linux的/ * nix中)或体系结构(32/64位),然后你可以捆绑SWT的罐子每个目标平台与安装,然后在运行时动态加载正确的(或者让你的安装程序复制在安装时正确的SWT JAR)。

if you want to have a single build that runs on different platforms (Win/Mac/Linux/*nix) or architectures (32/64 bit) then you can bundle the SWT jar for each target platform with your installer and then load the correct one dynamically at runtime (or have your installer copy the correct SWT jar at installation time).

例如。说你要支持32位和64位Windows和Linux你会SWT的罐子:

E.g. say you want to support 32 and 64 bit Windows and Linux you would have SWT jars:

lib/swt_win_32.jar
lib/swt_win_64.jar
lib/swt_linux_32.jar
lib/swt_linux_32.jar

请Ant脚本/安装包括所有这些(他们是约1.6MB个),然后在你的code运行时可以使用Java系统属性检测操作系统和架构

Make your ant script / installer include all of these (they are about 1.6MB each) and then at runtime in your code you can detect the OS and architecture using the Java system properties

System.getProperty("os.name");
System.getProperty("os.arch");

要建立正确的jar文件的名称。

to build the name of the correct jar file.

在运行时加载的罐子可以用自定义类加载器或调用受保护的方法来执行 URLClassloader.addURL(网址URL)使用反射。

Loading the jar at runtime can be performed by a custom classloader or by calling the protected method URLClassloader.addURL(URL url) using reflection.

我已经把工作code来执行在我的网站这个确切任务:<一href=\"http://www.chrisnewland.com/select-correct-swt-jar-for-your-os-and-jvm-at-runtime-191\">http://www.chrisnewland.com/select-correct-swt-jar-for-your-os-and-jvm-at-runtime-191

I've put working code to perform this exact task on my website: http://www.chrisnewland.com/select-correct-swt-jar-for-your-os-and-jvm-at-runtime-191

如果你能忍受的code-气味那么它是一个快速的解决方案,以一种非常常见的SWT的问题。

If you can stand the code-smell then it's a quick solution to a very common SWT problem.

这篇关于SWT罐子不同的平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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