Bulding an multi-platform SWT application using Ant

允我心安 提交于 2019-12-13 20:24:24

问题


I'm writing an SWT application which can be used on Windows (32/64 bit) and Mac OSX (32/64 bit).

Apart from the JRE I rely on the SWT library found here. I can find four versions of the SWT library depending upon my target platforms (as mentioned above).

When building my application, how can I compile using the correct SWT Jar? If possible, I'd like to try and avoid hard-coding the Jar version, platform and architecture. The SWT Jars are named like this:

  • swt-win32-x86_64.jar
  • swt-win32-x86_32.jar
  • swt-macosx-x86_32.jar
  • swt-macosx-x86_64.jar

(My project will be an open source project. I'd like people to be able to download the source and build it and therefore I've thought of including all the four versions of the SWT Jars in the source distribution. I hope this is the correct approach of publishing code relying on third-part libraries.)

Thanks everyone.


回答1:


I've tried to accomplish it like this: I've installed the Ant Contrib tasks because it supports if statements. I've modified my build file to use to detect the OS platform and architecture.

When compiling, it uses all the 4 SWT Jars from my lib.dir but after compilation, it copies over only the necessary SWT Jar to my build directory. I guess this would keep my size of my final ZIP much smaller than keeping all four JARs.

<target name="copy" depends="compile">
    <if>
    <os family="windows"/>
    <then>
        <exec dir="." executable="cmd" outputproperty="command.ouput">
            <arg line="/c SET ProgramFiles(x86)"/>
        </exec>
        <if>
            <contains string="${command.ouput}" substring="Program Files (x86)"/>
            <then>
                <copy file="${lib.dir}/swt-win32-x86_64.jar" tofile="${jar.dir}/SWT.jar"/>
            </then>
            <else>
                <copy file="${lib.dir}/swt-win32-x86_32.jar" tofile="${jar.dir}/SWT.jar"/>
            </else>
        </if>
    </then>
    <elseif>
        <os family="unix"/>
        <then>
            <exec dir="." executable="/bin/sh" outputproperty="command.ouput">
                <arg line="/c uname -m"/>
            </exec>
            <if>
                <contains string="${command.ouput}" substring="_64"/>
                <then>
                    <copy file="${lib.dir}/swt-macosx-x86_64.jar" tofile="${jar.dir}/SWT.jar"/>
                </then>
                <else>
                    <copy file="${lib.dir}/swt-macosx-x86_32.jar" tofile="${jar.dir}/SWT.jar"/>
                </else>
            </if>
        </then>
    </elseif>
    </if>
</target>

This seems to work so far. I'll test it some more and add a comment.



来源:https://stackoverflow.com/questions/10894483/bulding-an-multi-platform-swt-application-using-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!