为SWT应用程序构建多平台可执行文件(Eclipse) [英] Build multi-platform executable for a SWT application (Eclipse)

查看:166
本文介绍了为SWT应用程序构建多平台可执行文件(Eclipse)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于Eclipse的SWT应用程序,而不是使用Maven。

I have an Eclipse-based SWT application, not using Maven.

我的应用程序针对多个操作系统(CentOS,Windows和Mac)。

My application targets multiple operating systems (CentOS, Windows, and Mac).

唯一不与操作系统无关的jar文件是SWT库,它特定于每种操作系统类型,更不用说处理器类型(x86和/或x64)。

The only jar file that is not OS agnostic is the SWT library, which is specific to each OS type, not to mention processor type (x86 and/or x64).

我看到了这个其他问题,但目标是Maven,我没有使用Maven。

I saw this other issue, but that targets Maven and I am not using Maven.

我已通过以下方式将org.eclipse.swt添加到我的项目中概述的程序,包括整个SWT下载的ZIP文件。这指定了Package Explorer中的第二个项目。

I have "org.eclipse.swt" added to my project by following an outlined procedure and including the entire SWT downloaded ZIP file. That specifies a second project in Package Explorer.

早些时候,当我刚刚包含swt.jar时,它有点容易,因为我只需要删除jar,包括新的,重建,但这是一个痛苦。现在我使用整个SWT ZIP,这个过程有点乏味而且不专业。

Earlier when I was just including swt.jar, it was a bit easier, as I just had to delete the jar, include the new one, and rebuild, but that was a a pain. Now that I use the entire SWT ZIP, the process is a bit tedious and not professional.

有什么步骤,所以当我指定右键单击> Java>时Runnable JAR文件创建一个可执行的jar,我得到3个(或多个)不同的jar文件,每个操作系统一个? Visual Studio做得很好,只是我不知道如何在Eclipse中这样做。

What are the steps, so that when I specify "right click > Java > Runnable JAR file" to create a single executable jar that I get 3 (or however many) different jar files, one per operating system? Visual Studio does that nicely, just I do not know how to do that here in Eclipse.

更新:
要回答评论,我想添加JFace支持,因为我想使用TableViewer功能,这需要JFace。 Eclipse有这个页面,在第一部分中概述了如何添加SWT。这些步骤除了在最后添加源代码外都有效,但这是偏离主题的。

UPDATE: To answer a comment, I wanted to add JFace support, as I want to use the TableViewer feature, which requires JFace. Eclipse has this page outlining in the first part how to add in SWT. The steps work except for adding the source code at the end, but that is off-topic.

我按照64位Windows的步骤进行操作,但我必须支持CENTOS和Mac目前会很好。

I followed the steps for 64-bit Windows, however I have to support CENTOS and Mac would be a "would be nice" at the moment.

独立于swt.jar经文org.eclipse.swt,我想要一个干净的方式(想想带有.Net的Visual Studio为我的应用程序构建一个可运行/可执行的jar文件,每个支持的操作系统类型一个。我的想法是我指定构建(在我设置之后的任何菜单键序列)并且每个目标OS获得一个可执行jar文件。

Independent of swt.jar verses org.eclipse.swt, I would like a clean way (think Visual Studio with .Net) to build a single runnable/executable jar file for my application, one per supported OS type. My thought is that I specify build (whatever menu key sequence after I set things up) and I get one single executable jar file per target OS.

推荐答案

是的,尽管我说你可以为所有平台创建一个 .jar 文件,但我无法让它正常工作。

Right, despite me saying that you can create a single .jar file for all platforms, I wasn't able to get it working properly.

但是,我设法启动并运行了一个示例项目,它将创建一个单独的 .jar 只需使用Ant即可为每个平台提供文件。

However, I managed to get an example project up and running that will create a separate .jar file for each platform for you by simply using Ant.

您可以下载整个项目这里

构建脚本如下所示:

<project name="RandomApp" basedir="." default="clean-build">

    <property name="src.dir" value="src" />

    <!-- Define the necessary paths -->
    <property name="build.dir" value="bin_temp" />
    <property name="lib.dir" value="lib" />
    <property name="lib.deploy.dir" value="lib_swt" />
    <property name="classes.dir" value="${build.dir}/classes" />
    <property name="jar.dir" value="${build.dir}/jar" />

    <!-- Define the main class -->
    <property name="main-class" value="org.baz.desktop.randomapp.RandomApp" />

    <!-- Define the class path -->
    <path id="classpath">
        <fileset dir="${lib.dir}" includes="**/*.jar" />
        <fileset dir="${lib.deploy.dir}" includes="**/swt_linux_gtk_x86.jar" />
    </path>

    <!-- Clean previously built files -->
    <target name="clean">
        <delete dir="${build.dir}" />
    </target>

    <!-- Compile the project -->
    <target name="compile">
        <mkdir dir="${classes.dir}" />
        <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" includeantruntime="false" />
    </target>

    <!-- Define classpath and create the jar folder -->
    <target name="pre_jar" depends="compile">
        <pathconvert property="manifest.classpath" pathsep=" ">
            <path refid="classpath" />
            <mapper>
                <chainedmapper>
                    <flattenmapper />
                    <globmapper from="*.jar" to="*.jar" />
                </chainedmapper>
            </mapper>
        </pathconvert>

        <mkdir dir="${jar.dir}" />
    </target>

    <!-- Create the jar files -->
    <target name="jar" depends="pre_jar">
        <!-- Linux 32bit -->
        <jar destfile="${jar.dir}/${ant.project.name}_linux_gtk_x86.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
                <attribute name="Rsrc-Main-Class" value="${main-class}" />
                <attribute name="Class-Path" value="." />
                <attribute name="Rsrc-Class-Path" value="./ ${manifest.classpath}" />
            </manifest>

            <zipgroupfileset dir="${lib.dir}" includes="**/jar-in-jar-loader.jar" />
            <zipfileset dir="${lib.deploy.dir}" includes="**/swt_linux_gtk_x86.jar" />
            <zipfileset dir="${lib.dir}" includes="**/*.jar" excludes="**/jar-in-jar-loader.jar" />
        </jar>
        <!-- Linux 64bit -->
        <jar destfile="${jar.dir}/${ant.project.name}_linux_gtk_x64.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
                <attribute name="Rsrc-Main-Class" value="${main-class}" />
                <attribute name="Class-Path" value="." />
                <attribute name="Rsrc-Class-Path" value="./ ${manifest.classpath}" />
            </manifest>

            <zipgroupfileset dir="${lib.dir}" includes="**/jar-in-jar-loader.jar" />
            <zipfileset dir="${lib.deploy.dir}" includes="**/swt_linux_gtk_x64.jar" />
            <zipfileset dir="${lib.dir}" includes="**/*.jar" excludes="**/jar-in-jar-loader.jar" />
        </jar>
        <!-- Windows 32bit -->
        <jar destfile="${jar.dir}/${ant.project.name}_win32_x86.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
                <attribute name="Rsrc-Main-Class" value="${main-class}" />
                <attribute name="Class-Path" value="." />
                <attribute name="Rsrc-Class-Path" value="./ ${manifest.classpath}" />
            </manifest>

            <zipgroupfileset dir="${lib.dir}" includes="**/jar-in-jar-loader.jar" />
            <zipfileset dir="${lib.deploy.dir}" includes="**/swt_win32_x86.jar" />
            <zipfileset dir="${lib.dir}" includes="**/*.jar" excludes="**/jar-in-jar-loader.jar" />
        </jar>
        <!-- Windows 64bit -->
        <jar destfile="${jar.dir}/${ant.project.name}_win32_x64.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
                <attribute name="Rsrc-Main-Class" value="${main-class}" />
                <attribute name="Class-Path" value="." />
                <attribute name="Rsrc-Class-Path" value="./ ${manifest.classpath}" />
            </manifest>

            <zipgroupfileset dir="${lib.dir}" includes="**/jar-in-jar-loader.jar" />
            <zipfileset dir="${lib.deploy.dir}" includes="**/swt_win32_x64.jar" />
            <zipfileset dir="${lib.dir}" includes="**/*.jar" excludes="**/jar-in-jar-loader.jar" />
        </jar>
        <!-- MacOS 32bit -->
        <jar destfile="${jar.dir}/${ant.project.name}_macos_x86.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
                <attribute name="Rsrc-Main-Class" value="${main-class}" />
                <attribute name="Class-Path" value="." />
                <attribute name="Rsrc-Class-Path" value="./ ${manifest.classpath}" />
            </manifest>

            <zipgroupfileset dir="${lib.dir}" includes="**/jar-in-jar-loader.jar" />
            <zipfileset dir="${lib.deploy.dir}" includes="**/swt_macosx_x86.jar" />
            <zipfileset dir="${lib.dir}" includes="**/*.jar" excludes="**/jar-in-jar-loader.jar" />
        </jar>
        <!-- MacOS 64bit -->
        <jar destfile="${jar.dir}/${ant.project.name}_macos_x64.jar" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
                <attribute name="Rsrc-Main-Class" value="${main-class}" />
                <attribute name="Class-Path" value="." />
                <attribute name="Rsrc-Class-Path" value="./ ${manifest.classpath}" />
            </manifest>

            <zipgroupfileset dir="${lib.dir}" includes="**/jar-in-jar-loader.jar" />
            <zipfileset dir="${lib.deploy.dir}" includes="**/swt_macosx_x64.jar" />
            <zipfileset dir="${lib.dir}" includes="**/*.jar" excludes="**/jar-in-jar-loader.jar" />
        </jar>
    </target>

    <target name="clean-build" depends="clean,jar" />

</project>

项目本身没什么特别的,只是一个JFace 对话表明JFace也可以。

The project itself is nothing fancy, just a JFace Dialog to show that JFace works as well.

注意

要在Windows机器上进行编译,您必须更改一行:

To make this compile on a Windows machine, you will have to change one line:

<fileset dir="${lib.deploy.dir}" includes="**/swt_linux_gtk_x86.jar" />

将其更改为:

<fileset dir="${lib.deploy.dir}" includes="**/swt_win32_x64.jar" />

<fileset dir="${lib.deploy.dir}" includes="**/swt_win32_x86.jar" />

基本上,此行必须代表您的系统,即您正在编译的系统。

Basically, this line has to represent YOUR system, i.e., the system you're compiling on.

这篇关于为SWT应用程序构建多平台可执行文件(Eclipse)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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