ANT - How i cant move File to JAR - java

i've had edited my ANT build process. Here is my working list:
create a copy of the src folder and a selfwritten AntTask Obfuscated all Strings
ANT creates an JAR with <jar>
the JAR will be Obfuscated by ProGuard
An additional file will must be copied to the JAR
JAR will be signed
The bodled step is my Question. How i can copy a single file to the root directory of the JAR. I must make this step here! Before or after won't work: Before: ProGuard will be try to obfuscate this file and gives Exceptions. After cant work, the file must be signed.
Anyone have an smart idea?
Here a minified version of my ANT build script:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<project basedir="." default="default" name="DEMO">
<property environment="env" />
<property name="debuglevel" value="source,lines,vars" />
<property name="target" value="1.7" />
<property name="source" value="1.7" />
<!-- Applet Informationen -->
<property name="version" value="1.0.0" />
<!-- Start Build process -->
<target name="default">
<echo message="Copy source" />
<delete dir="builds/temp/" />
<mkdir dir="builds/temp/" />
<copydir src="src" dest="builds/temp/" />
<echo message="Obfuscate Strings" />
<taskdef resource="task.properties" classpath="libs/MyStringHelper.jar" />
<mystringhelper dir="builds/temp/" name="_X.class" decoder="MyClass.myMethod" imports="import test.MyClass;" />
<javac srcdir="builds/temp/" destdir="bin" />
<sleep seconds="1" />
<echo message="Create JAR Archive with Version ${version}" />
<jar destfile="builds/${name}${version}.jar" basedir="bin">
<manifest>
<attribute name="Application-Name" value="${name}" />
<attribute name="Application-Library-Allowable-Codebase" value="*.domain.com localhost" />
<attribute name="Caller-Allowable-Codebase" value="*.domain.com localhost" />
<attribute name="Codebase" value="*.domain.com localhost" />
<attribute name="Permissions" value="all-permissions" />
<attribute name="Author" value="Adrian Preuss" />
<attribute name="Main-Class" value="main.Run" />
</manifest>
</jar>
<echo message="Obfuscate the Archive" />
<taskdef resource="proguard/ant/task.properties" classpath="libs/proguard.jar" />
<proguard printmapping="proguard.map" overloadaggressively="off" repackageclasses="" renamesourcefileattribute="SourceFile">
<injar file="builds/${name}${version}.jar" />
<outjar file="builds/__${name}${version}.jar" />
<libraryjar file="${java.home}/lib/rt.jar" />
<libraryjar file="libs/ant.jar" />
<libraryjar file="libs/gradle-plugins-1.3.jar" />
<libraryjar file="libs/gradle-base-services-1.3.jar" />
<libraryjar file="libs/gradle-core-1.3.jar" />
<libraryjar file="libs/groovy-all-1.8.6.jar" />
<libraryjar file="libs/kenv.zip" />
<keeppackagename name="main" />
<keep access="public" name="main.Run">
<method access="public" type="void" name="changeLanguage" parameters="java.lang.String" />
</keep>
</proguard>
<delete file="builds/${name}${version}.jar" failonerror="false" />
<move file="builds/__${name}${version}.jar" tofile="builds/${name}${version}.jar" />
<!--
##
## ADD the File "builds/temp/_XA.class" to the JAR
##
## Info: the _XA.class is'nt an Java-Class file!
-->
<echo message="Roll up the code signing" />
<signjar jar="builds/${name}${version}.jar" alias="${name}" keystore="${name}.keystore" storepass="${password}" preservelastmodified="true" />
<echo message="Verify code signing" />
<verifyjar jar="builds/${name}${version}.jar" alias="${name}" storepass="${password}"/>
<echo message="Copy applet to local environment" />
<copy file="builds/${name}${version}.jar" tofile="C:/devsrv/htdocs/${name}${version}.jar" failonerror="false" />
<echo message="Cleanup,..." />
<!-- .... -->
</target>
</project>

This is a part from my ant build file including all xml, jpg, gif and png:
<!-- ============================================================== -->
<!-- Build application -->
<!-- ============================================================== -->
<target name="build" depends="make-bin-dir" description="Build application">
<javac srcdir="${src.dir}" destdir="${bin.dir}" debug="on" classpathref="javac.classpath" />
<copy todir="${bin.dir}">
<fileset dir="${src.dir}">
<include name="**/*.xml" />
<include name="**/*.jpg" />
<include name="**/*.gif" />
<include name="**/*.png" />
</fileset>
</copy>
</target>
To only include one file just put the full name in include name= "fullnamehere" />
Sorry...haven't seen your part to add...
Try it like this:
include name= "builds/temp/_XA.class" />

Since a Jar is really a Zip file, you could unzip the jar to a temp directory after proguard does its thing, add the _XA.class file where you want in in that temp dir, and re-create the jar file before signing.

Related

How to distribute an app on Mac?

What is the current best way to distribute an application on a Mac?
What I would like is a build.xml that, when built (in NetBeans) will output an .exe (windows) and .app (mac) into the dist folder.
I currently have a build.xml that compacts the program into a .zip file for distribution, but would like to add an .app and .exe for mac and windows.
Here is my current build.xml that outputs to a zip file.
<?xml version="1.0" encoding="UTF-8"?>
<project name="name" default="default" basedir=".">
<description></description>
<import file="nbproject/build-impl.xml"/>
<property file="version.properties"/>
<property name="version" value="${version.major}.${version.minor}.${version.patch}" />
<property name="executable.name" value="company-${version.product.name}-${version}" />
<target name="-post-jar" description="Generates a versioned name for the JAR file">
<mkdir dir="LOGS" />
<move file="dist/${ant.project.name}.jar" tofile="dist/${executable.name}.jar" />
<antcall target="generate-run-scripts" />
<antcall target="deliverable-osx" />
<antcall target="deliverable-windows" />
</target>
<target name="generate-run-scripts" description="Generate batch files to run the application">
<echo file="dist/run.bat">
java -cp ${executable.name}.jar -Djava.util.logging.config.file=logging.properties -Xmx2048m -Dcom.sun.management.jmxremote classname
</echo>
<echo file="dist/run.sh">#!/bin/sh
java -cp ${executable.name}.jar -Djava.util.logging.config.file=logging.properties -Xmx2048m -Dcom.sun.management.jmxremote classname
</echo>
</target>
<target name="deliverable-windows" description="Deployment files for Windows runtime">
<property name="zip.name" value="Project-${version}-windows" />
<zip destfile="dist/${zip.name}.zip">
<zipfileset file="dist/${executable.name}.jar" />
<zipfileset file="logging.properties"/>
<zipfileset dir="dist/lib" includes="*.jar" prefix="lib" />
<zipfileset file="dist/run.bat"/>
<zipfileset dir="LOGS" excludes="*" />
<zipfileset dir="files" excludes="*" />
<zipfileset file="changelog.txt"/>
</zip>
</target>
<target name="deliverable-osx" description="Deployment files for Apple OS-X runtime">
<property name="zip.name" value="Project-${version}-OSX" />
<zip destfile="dist/${zip.name}.zip">
<zipfileset file="dist/${executable.name}.jar" />
<zipfileset file="logging.properties"/>
<zipfileset dir="dist/lib" includes="*.jar" prefix="lib" />
<zipfileset file="dist/run.sh" filemode="755" />
<zipfileset dir="LOGS" excludes="*" />
<zipfileset dir="files" excludes="*" />
<zipfileset file="changelog.txt"/>
</zip>
</target>
</project>
Here is my attempt at outputting an .app file. It outputs a .app file, but displays an error message every time I try running it. (Although after running it again its not even outputting an .app file).
I used Packaging a Java App to create the build.xml.
<?xml version="1.0" encoding="UTF-8"?>
<project name="name" default="default" basedir=".">
<description></description>
<import file="nbproject/build-impl.xml"/>
<property file="version.properties"/>
<property name="version" value="${version.major}.${version.minor}.${version.patch}" />
<property name="executable.name" value="company-${version.product.name}-${version}" />
<property environment="env" />
<taskdef name="bundleapp"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
<target name="ai_debug">
<bundleapp outputdirectory="dist"
name="Project"
displayname="Project-${version}"
identifier="classname"
mainclassname="classname">
<runtime dir="${java.home}" />
<classpath file="dist/Project.jar"/>
</bundleapp>
</target>
</project>

Authentication Provider does not appear in the list of Authenticators in WebLogic Server Version: 12.1.3.0.0

I've just created an Authentication Provider for WebLogic Server Version: 12.1.3.0.0, put the jar in the lib of the domain, but does not appear in the List of Providers to select
<?xml version="1.0"?>
<!DOCTYPE MBeanType SYSTEM "commo.dtd">
<!-- MBean Definition File (MDF) for the MMR WS Authenticator See documentation at: http://docs.oracle.com/cd/E13212_01/wles/docs42/dvspisec/mdf_ref.html Since it is for an identity asserter, it must extend the weblogic.management.security.authentication.IdentityAsserter mbean. The Name and DisplayName must be the same. They specify the name that will appear on the console for this provider. Set the PeristPolicy to "OnUpdate" so that if an attribute value is changed, the new value is written to disk immediately. See the "Developing Security Services" manual for more info. Note that since this is an xml document, you can't use double quotes directly. Instead you need to use " Note that setting "Writeable" to "false" on an attribute makes the attribute read-only. The default is read-write. -->
-<MBeanType PersistPolicy="OnUpdate" Extends="weblogic.management.security.authentication.Authenticator" Package="fr.telecom.security.authentication.provider.mbean" Name="MMRWSAuthenticator">
<!-- You must set the value of the ProviderClassName attribute (inherited from the weblogic.management.security.Provider mbean) to the name of the java class you wrote that implements the weblogic.security.spi.AuthenticationProvider interface. You can think of the provider's mbean as the factory for your provider's runtime implementation. -->
<MBeanAttribute Name="ProviderClassName" Default=""fr.telecom.security.authentication.provider.MMRWSAuthenticationProviderImpl"" Preprocessor="weblogic.management.configuration.LegalHelper.checkClassName(value)" Writeable="false" Type="java.lang.String"/>
<!-- You must set the value of the Description attribute (inherited from the weblogic.management.security.Provider mbean) to a brief description of your provider. It is displayed in the console. -->
<MBeanAttribute Name="Description" Default=""MMR WS Authenticator"" Writeable="false" Type="java.lang.String"/>
<!-- You must set the value of the Version attribute (inherited from the weblogic.management.security.Provider mbean) to your provider's version. There is no required format. -->
<MBeanAttribute Name="Version" Default=""1.0"" Writeable="false" Type="java.lang.String"/>
</MBeanType>
This is my build.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!--
This project is not entirely handled by Maven, so be careful when generating the artifact, and use Ant with its default target.
-->
<project name="devices-ws-authentication-provider" default="all" basedir=".">
<echo>
Remember to execute the command below before doing an Ant:
%MW_HOME%\wlserver\server\bin\setWLSEnv.cmd
</echo>
<property name="src-java" value="src/main/java" />
<property name="mbean" value="src/mbean" />
<target name="all" depends="build" />
<target name="build" depends="clean,build.mdf,build.mjf" />
<target name="clean">
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${mbean}" includes="**/*"/>
</delete>
<delete file="target/devices-ws-authentication-provider-1.0.0-SNAPSHOT.jar" failonerror="false" />
<mkdir dir="target" />
<echo message="Clean finish" />
</target>
<!-- helper to build an MDF (mbean definition file) -->
<target name="build.mdf">
<java dir="${basedir}" fork="false" classname="weblogic.management.commo.WebLogicMBeanMaker">
<arg line="-files ${mbean}" />
<arg value="-createStubs" />
<arg line="-MDF src/main/resources/TntWSAuthenticator.xml" />
</java>
<echo message="Created Supporting Classes" />
<move todir="${src-java}/fr/telecom/security/authentication/provider/mbean" file="${mbean}/TntWSAuthenticatorImpl.java" />
<move todir="${src-java}/fr/telecom/security/authentication/provider/mbean" file="${mbean}//fr/telecom/security/authentication/provider/mbean/TntWSAuthenticatorMBean.java" />
</target>
<target name="build.mjf">
<mkdir dir="${mbean}" />
<copy todir="${mbean}">
<fileset dir="src/main/java">
<include name="**/*" />
</fileset>
<fileset dir="src/main/resources">
<include name="**/*" />
</fileset>
</copy>
<java dir="${basedir}" fork="false" classname="weblogic.management.commo.WebLogicMBeanMaker">
<arg line="-MJF target/devices-ws-authentication-provider-1.0.0-SNAPSHOT.jar" />
<arg line="-files ${mbean}" />
</java>
<echo message="Mbean JAR created." />
<!-- Do a small cleanup after building the JAR, in order to not have duplicated sources / classes in source paths -->
<!--
<delete includeemptydirs="true" failonerror="false">
<fileset dir="${mbean}" includes="fr/telecom/security/authentication/provider/*.java" />
<fileset dir="${mbean}" includes="fr/telecom/domain/**/*.java" />
<fileset dir="${mbean}" includes="commo.dtd" />
<fileset dir="${mbean}" includes="rebel.xml" />
<fileset dir="${mbean}" includes="TntWSAuthenticator.xml" />
</delete>
-->
</target>
<target name="install" depends="build">
<copy todir="${user.home}/devices/lib" file="target/devices-ws-authentication-provider-1.0.0-SNAPSHOT.jar" />
</target>
</project>
opening the generated ear I see that there is some missing folders and files, like
/schemacom_bea_xml/element
/schemacom_bea_xml/namespace
/schemacom_bea_xml/system
/schemacom_bea_xml/type
/weblogic/
WLS providers is a nightmare, I have already developed two and now I am using Spring Security :) for the shake of simplicity and portability.
Well, I read your build.xml and it result strange for me, but the most obvious thing I see is that you lack the following argument:
<arg line="-targetNameSpace your.namespace.here" />
inside WebLogicMBeanMake ant rule. Try it, but if it does not work I will recommend you to redo. I can provide you some samples.
Edit
In response to your comment, I will include here a sample that I have already working in a real project.
This is a build.xml file to be run with and. To run this sample it is required to have WLS 12c installed. Before run ant buildAndDeploy you have to run ${WLS_HOME}/server/bin/setWLSEnv.sh script to prepare environment.
You have to adapt global properties at the beginning of the file.
<project name="ldap-db-provider" default="buildAndDeploy" basedir=".">
<description>Custom Authentication Provider Build</description>
<!-- global properties -->
<property name="base.dir" location="." />
<property name="bea.home" location="/opt/weblogic/Oracle/Middleware/Oracle_Home" />
<property name="mbean.maker" location="${bea.home}/wlserver/modules/com.bea.core.mbean.maker_2.1.0.0.jar" />
<property name="wls.home" value="${bea.home}/wlserver" />
<property name="wls.lib.dir" value="${wls.home}/server/lib" />
<property name="mbeantypes.dir" value="${wls.lib.dir}/mbeantypes" />
<property name="jar.file.name" value="your-name-for-the-provider-package.jar" />
<property name="src.dir" value="${base.dir}/src" />
<property name="provider.src.dir" value="${src.dir}/es" />
<property name="build.dir" value="${base.dir}/build" />
<property name="targetNamespace" value="your.target.name.space"/>
<property name="mbean.impl.name" value="YouBeanName" />
<property name="mbean.package" value="your/mbean/pacakage/name" />
<target name="updateSources">
<copy todir="${src.dir}/${mbean.package}" flatten="true">
<fileset dir="${build.dir}">
<include name="${mbean.impl.name}Impl.java" />
</fileset>
</copy>
<copy todir="${src.dir}/${mbean.package}" flatten="true">
<fileset dir="${build.dir}/${mbean.package}">
<include name="**/*.java" />
</fileset>
</copy>
</target>
<target name="buildAndDeploy" depends="clean">
<mkdir dir="${build.dir}" />
<copy todir="${build.dir}" flatten="true">
<fileset dir="${wls.lib.dir}">
<include name="commo.dtd" />
</fileset>
</copy>
<copy todir="${build.dir}" flatten="true">
<fileset dir="${provider.src.dir}">
<include name="**/*.xml" />
<include name="**/*.java" />
</fileset>
</copy>
<java
classname="weblogic.management.commo.WebLogicMBeanMaker"
fork="true" failonerror="true">
<!-- <classpath refid="build.path"/> -->
<arg line="-files ${build.dir}" />
<arg value="-createStubs" />
<arg line="-MDF ${build.dir}/${mbean.impl.name}-Mbean.xml" />
</java>
<echo message="Created Supporting Classes" />
<java
classname="weblogic.management.commo.WebLogicMBeanMaker"
fork="true" failonerror="true">
<!-- <classpath refid="build.path"/> -->
<arg line="-MJF ${build.dir}/${jar.file.name}" />
<arg line="-targetNameSpace ${targetNamespace}" />
<arg line="-files ${build.dir}" />
</java>
<echo message="Created Mbean Jar" />
<!-- Deploy the sample security providers -->
<copy todir="${mbeantypes.dir}" flatten="true">
<fileset dir="${build.dir}">
<include name="${jar.file.name}" />
</fileset>
</copy>
</target>
<target name="clean">
<delete quiet="true" dir="${build.dir}" />
<delete>
<fileset dir="${src.dir}/${mbean.package}" includes="**/*.java" />
</delete>
<delete quiet="true" file="${mbeantypes.dir}/${jar.file.name}" />
</target>
</project>
Hope it helps!

Classpath jar (ojdbc6.jar) is not included after jar create via Ant

I was able to generate a jar file with manifest.mf. However, when i run the jar file in the command prompt, it looks for the oracle driver. I'm pretty sure that I have added this in eclipse project build path.
My build.xml:
<?xml version="1.0"?>
<project name="converter" default="main" basedir=".">
<property name="projectName" value="Converter" />
<property name="src.dir" value="src"/>
<property name="web.dir" value="war"/>
<property name="lib.dir" value="lib"/>
<property name="dist.dir" location="dist" />
<property name="dist.lib.dir" location="dist/lib" />
<property name="build.dir" value="${web.dir}/WEB-INF/classes"/>
<property name="name" value="converter"/>
<property name="main-class" value="com.ouc.mv90.conversion.CSVtoMV90Converter" />
<target name="init">
<mkdir dir="${build.dir}" />
</target>
<!-- external libraries classpath, we don't need sources and javadoc -->
<path id="classpath">
<fileset dir="${basedir}/">
<include name="${lib.dir}/*.jar" />
<exclude name="${lib.dir}/*sources.jar"/>
<exclude name="${lib.dir}/*javadoc.jar"/>
</fileset>
</path>
<!-- To work with external libraries, need classpath to compile -->
<target name="compile" depends="init" description="compile the source ">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${build.dir}" classpathref="classpath" />
</target>
<!-- constructs the external libraries classpath name -->
<pathconvert property="classpath.name" pathsep=" ">
<path refid="classpath" />
<mapper>
<chainedmapper>
<flattenmapper />
<globmapper from="*.jar" to="lib/*.jar" />
</chainedmapper>
</mapper>
</pathconvert>
<target name="copy-dependencies">
<copy todir="${dist.lib.dir}">
<fileset dir="${lib.dir}" includes="**/*.jar" excludes="**/*sources.jar, **/*javadoc.jar" />
</copy>
</target>
<!-- jar it, and declares the ext libraries in manifest.mf file -->
<target name="jar" depends="compile, copy-dependencies" description="package, output to JAR">
<echo message="classpath.name : ${classpath.name} " />
<mkdir dir="${dist.dir}" />
<mkdir dir="${dist.lib.dir}" />
<jar jarfile="${dist.dir}/${projectName}.jar" basedir="${build.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}" />
<attribute name="Class-Path" value="${classpath.name}" />
</manifest>
</jar>
</target>
<target name="clean" description="clean up">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Default, run this -->
<target name="main" depends="clean, compile, jar" />
</project>
MANIFEST.mf
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.2
Created-By: 1.6.0_43-b01 (Sun Microsystems Inc.)
Main-Class: com.ouc.mv90.conversion.CSVtoMV90Converter
Class-Path: lib/ojdbc6.jar

Build one jar per platform for multi-platform SWT application

There are a couple of questions to this topic already, but none of them seem to work properly.
Here is a list of them:
Bulding an multi-platform SWT application using Ant
Build multi-platform executable for a SWT application (Eclipse)
Build multi-platform executable for a SWT application using maven
SWT jar for different platform
Create cross platform Java SWT Application
My requirement is to build an ant script that creates one jar per platform, i.e. one for Windows x86, one for Windows x64, Linux x86/x64 and so on.
Does anyone have any further insight?
Using the aforementioned methods, I was not able to produce a workable solution. It either ended with the SWT jar file not automatically being loaded or it not being included in the classpath.
If someone can come up with a working example (ideally including the complete source code), that would be grand!
Right, so I finally came up with a solution that I successfully tested on three platforms.
The two magic components are the jar-in-jar-loader and a proper build script.
The build script with comments can be found here:
<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" />
</path>
<!-- Define the class path -->
<path id="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" excludes="**/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>
What it basically does is define a base classpath without any SWT library.
Then it creates platform specific classpaths using the base one and adding the appropriate platform SWT library.
The jar task then creates a separate jar for each platform using these classpaths and the jar-in-jar-loader.
And that's it, a fully automated way of generating jars for each (supported) platform.
I've created an example project that people can download and test out. It's an easy starting point for a multi-platform application.
https://www.dropbox.com/s/ianrbl4bn0fmsdi/SWTApplication.7z
Update:
I've managed to significantly shorten the ant script by making proper use of macrodef :)

Hibernate configuration files in an Ant-built WAR file

I have a web app in Eclipse that is working fine. I have built a war file using the ant script below, it works until the program attempts to access Hibernate:
<?xml version="1.0" encoding="UTF-8"?>
<!-- !DOCTYPE removes the warning:
No grammar constraints (DTD or XML schema) detected for the document.
-->
<!DOCTYPE project>
<project name="Audiclave" default="Deploy" basedir=".">
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="build.classes" location="build/classes" />
<property name="docs.dir" location="docs" />
<property name="web.dir" location="WebContent" />
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean">
<delete dir="${build.classes}" />
<delete dir="${build.dir}" />
<delete dir="${docs.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir">
<mkdir dir="${build.classes}" />
<mkdir dir="${build.dir}" />
<mkdir dir="${docs.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<path id="compile.classpath">
<fileset dir="${web.dir}/WEB-INF/lib">
<include name="*.jar" />
</fileset>
</path>
<target name="compile" depends="clean,makedir">
<javac srcdir="${src.dir}" debug="true" destdir="${build.classes}">
<classpath refid="compile.classpath" />
</javac>
</target>
<!-- Creates Javadoc -->
<target name="docs" depends="compile">
<javadoc packagenames="src" sourcepath="${src.dir}" destdir="${docs.dir}">
<!-- Define which files / directory should get included, we include all -->
<fileset dir="${src.dir}">
<include name="**" />
</fileset>
</javadoc>
</target>
<target name="Deploy">
<war destfile="${build.dir}/audiClave.war" webxml="${web.dir}/WEB-INF/web.xml">
<!-- Include the compiled classes from the compile target -->
<classes dir="${build.classes}" />
<!-- Include any configuration files (hibernate) -->
<fileset dir="${src.dir}" includes="**/*.xml" />
<!-- Include any web content -->
<fileset dir="${web.dir}" />
<lib dir="${web.dir}/WEB-INF/lib" />
</war>
</target>
</project>
The problem I am having is the positioning of the Hibernate config files. In my application they are in :
audiClave\src
but in the deployed app the xml files are in:
audiClave
whereas I think they need to be in :
audiClave\WEB-INF\classes
How do I make the statement:
<fileset dir="${src.dir}" includes="**/*.xml" />
send the files to the WEB-INF\classes directory (if that's where they need to be).
EDIT
Changed the script to include the following and it worked correctly:
<target name="compile" depends="clean,makedir">
<javac srcdir="${src.dir}" debug="true" destdir="${build.classes}">
<classpath refid="compile.classpath" />
</javac>
<copy todir="${build.classes}">
<fileset dir="${src.dir}" includes="**/*.xml,**/*.properties"/>
</copy>
</target>
Ask Ant to <copy> the files into /WEB-INF/classes. You are correct - that's where they belong. Be sure to create the directory path.

Categories