Configuring a multi-platform SWT application using Ant

I am writing a SWT application that can be used on Windows (32/64 bit) and Mac OSX (32/64 bit).

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

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

  • svt-win32-x86_64.jar
  • svt-win32-x86_32.jar
  • SWT-MacOSX-x86_32.jar
  • SWT-MacOSX-x86_64.jar

(My project will be an open source project. I would like people to be able to download the source code and build it, and so I thought about incorporating all four versions of SWT Jars into the source distribution. I hope this is the right approach to publish code based on libraries of the third part.)

Thanks to everyone.

0
source share
1 answer

I tried to execute it as follows: I installed Ant Contrib tasks because it supports statements if. I modified my build file to use to determine the platform and OS architecture.

4 SWT Jars lib.dir, SWT Jar . , ZIP , JAR.

<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>

, , . .

0

Source: https://habr.com/ru/post/1538542/


All Articles