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

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

问题描述

我正在使用 JWebBrowser应用.此类属于DJ 项目.它需要 swt jar 才能执行.现在,我已将 Windows 的 swt jar 包含在应用程序的 jar 包装中.我想知道如何在同一个包装中包含适用于 linux/mac 的 swt jars?我正在使用 ant 来构建应用程序 jar.我应该为不同的平台构建不同的 swt jar 吗?

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?

推荐答案

如果您想拥有在不同平台 (Win/Mac/Linux/*nix) 或架构(32/64 位)上运行的单个构建,那么您可以将每个目标平台的 SWT jar 与您的安装程序捆绑在一起,然后在运行时动态加载正确的一个(或者让您的安装程序在安装时复制正确的 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 jar:

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),然后在您的代码运行时,您可以使用 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.

在运行时加载 jar 可以由自定义类加载器执行,也可以通过使用反射调用受保护的方法 URLClassloader.addURL(URL 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.

我已经在我的网站上放置了执行此确切任务的工作代码: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

如果你能忍受代码的味道,那么它是一个非常常见的 SWT 问题的快速解决方案.

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

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

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