栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

每个平台为一个多平台SWT应用程序构建一个jar

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

每个平台为一个多平台SWT应用程序构建一个jar

是的,所以我最终提出了一个在三个平台上成功测试过的解决方案。

两个魔术组件是jar-in-jar-loader和适当的构建脚本。

带有注释的构建脚本可以在这里找到:

<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" />    <property name="img.dir" value="img" />    <property name="res.dir" value="res" />    <!-- Define the main class -->    <property name="main-class" value="org.baz.desktop.randomapp.gui.RandomApp" />    <path id="base-classpath">        <fileset dir="${lib.dir}" includes="***.jar" />        <fileset dir="${lib.deploy.dir}" includes="**/swt_win32_x64.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>    <macrodef name="createclasspath">        <attribute name="name" />        <attribute name="swtlib" />        <sequential> <pathconvert property="@{name}.classpath" pathsep=" ">     <path refid="base-classpath" />     <fileset dir="${lib.deploy.dir}" includes="**/swt_@{swtlib}.jar" />     <mapper>         <chainedmapper>  <flattenmapper />  <globmapper from="*.jar" to="*.jar" />         </chainedmapper>     </mapper> </pathconvert>        </sequential>    </macrodef>    <!-- Define classpath and create the jar folder -->    <target name="pre_jar" depends="compile">        <!-- Linux 32bit -->        <createclasspath name="win86" swtlib="win32_x86" />        <!-- Linux 64bit -->        <createclasspath name="win64" swtlib="win32_x64" />        <!-- Windows 32bit -->        <createclasspath name="linux86" swtlib="linux_gtk_x86" />        <!-- Windows 64bit -->        <createclasspath name="linux64" swtlib="linux_gtk_x64" />        <!-- MacOS 32bit -->        <createclasspath name="macos86" swtlib="macos_x86" />        <!-- MacOS 64bit -->        <createclasspath name="macos64" swtlib="macos_x64" />        <mkdir dir="${jar.dir}" />    </target>    <macrodef name="createjar">        <attribute name="swtlib" />        <attribute name="swtclasspath" />        <sequential> <jar destfile="${jar.dir}/${ant.project.name}_@{swtlib}.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="./ @{swtclasspath}" />     </manifest>     <zipgroupfileset dir="${lib.dir}" includes="**/jar-in-jar-loader.jar" />     <zipfileset dir="${lib.deploy.dir}" includes="**/swt_@{swtlib}.jar" />     <zipfileset dir="${lib.dir}" includes="**jar-in-jar-loader.jar" /> </jar>        </sequential>    </macrodef>    <!-- Create the jar files -->    <target name="jar" depends="pre_jar">        <!-- Linux 32bit -->        <createjar swtlib="linux_gtk_x86" swtclasspath="${linux86.classpath}" />        <!-- Linux 64bit -->        <createjar swtlib="linux_gtk_x64" swtclasspath="${linux64.classpath}" />        <!-- Windows 32bit -->        <createjar swtlib="win32_x86" swtclasspath="${win86.classpath}" />        <!-- Windows 64bit -->        <createjar swtlib="win32_x64" swtclasspath="${win64.classpath}" />        <!-- MacOS 32bit -->        <createjar swtlib="macos_x86" swtclasspath="${macos86.classpath}" />        <!-- MacOS 64bit -->        <createjar swtlib="macos_x64" swtclasspath="${macos64.classpath}" />    </target>    <target name="clean-build" depends="clean,jar" /></project>

它的基本作用是定义 没有 任何SWT库的基类路径。然后,它使用基础路径创建平台特定的类路径,并添加适当的平台SWT库。

jar
然后,该任务使用这些类路径和jar-in-jar-loader为每个平台创建一个单独的jar。

就是这样,这是一种为每个(受支持的)平台生成jar的全自动方法。


我创建了一个示例项目,人们可以下载并进行测试。对于多平台应用程序来说,这是一个简单的起点。

https://www.dropbox.com/s/ianrbl4bn0fmsdi/SWTApplication.7z


更新

我已经通过适当使用

macrodef
:) 大大缩短了ant脚本。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/507250.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号