java - Build multi-platform executable for a SWT application (Eclipse) -


i have eclipse-based swt application, not using maven.

my application targets multiple operating systems (centos, windows, , mac).

the jar file not os agnostic swt library, specific each os type, not mention processor type (x86 and/or x64).

i saw other issue, targets maven , not using maven.

i have "org.eclipse.swt" added project following outlined procedure , including entire swt downloaded zip file. specifies second project in package explorer.

earlier when including swt.jar, bit easier, had delete jar, include new one, , rebuild, a pain. use entire swt zip, process bit tedious , not professional.

what steps, when specify "right click > java > runnable jar file" create single executable jar 3 (or many) different jar files, 1 per operating system? visual studio nicely, not know how here in eclipse.

update: answer comment, wanted add jface support, want use tableviewer feature, requires jface. eclipse has this page outlining in first part how add in swt. steps work except adding source code @ end, off-topic.

i followed steps 64-bit windows, have support centos , mac "would nice" @ moment.

independent of swt.jar verses org.eclipse.swt, clean way (think visual studio .net) build single runnable/executable jar file application, 1 per supported os type. thought specify build (whatever menu key sequence after set things up) , 1 single executable jar file per target os.

right, despite me saying can create single .jar file platforms, wasn't able working properly.

however, managed example project , running create separate .jar file each platform using ant.

you can download whole project here.

the build script looks this:

<project name="randomapp" basedir="." default="clean-build">      <property name="src.dir" value="src" />      <!-- define 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 main class -->     <property name="main-class" value="org.baz.desktop.randomapp.randomapp" />      <!-- define class path -->     <path id="classpath">         <fileset dir="${lib.dir}" includes="**/*.jar" />         <fileset dir="${lib.deploy.dir}" includes="**/swt_linux_gtk_x86.jar" />     </path>      <!-- clean built files -->     <target name="clean">         <delete dir="${build.dir}" />     </target>      <!-- compile project -->     <target name="compile">         <mkdir dir="${classes.dir}" />         <javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="classpath" includeantruntime="false" />     </target>      <!-- define classpath , create 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 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> 

the project nothing fancy, jface dialog show jface works well.


note:

to make compile on windows machine, have change 1 line:

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

change to:

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

or

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

basically, line has represent system, i.e., system you're compiling on.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -