Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

obfuscate in build.xml

807603Mar 2 2007 — edited Jan 30 2008
Hi,
does obfuscating jars in ant in windows not work? I have the following code & get the error that seems to be related to obfuscation.
<project name="sims" default="CustomerDist" basedir=".">

  <property file="ant.properties"/>
  <property environment="localenv"/>

  <!--
  <taskdef name="proguard" classname="proguard.ant.ProGuardTask" classpath="builder/proguard.jar" />
  -->
  <taskdef classpath="jcoverage.jar" resource="tasks.properties"/>

  <target name="init">
    <fail unless="PROPERTIESLOADED">missing PROPERTIESLOADED, have you renamed ant.properties.sample to ant.properties?</fail>

    <available property="elandlibs_DirectoryExists"
               file="${elandlibs}"
               type="dir"
               />
    <fail unless="elandlibs_DirectoryExists">Cannot find the shared 'javalibs' CVS project. Have you checked this project out of CVS and set the elandlibs property in ant.properties?</fail>

    <mkdir dir="${testbuild}"/>
    <mkdir dir="${build}"/>
    <mkdir dir="${build2}"/>
    <mkdir dir="${dist}"/>
    <mkdir dir="distInternal"/>
    <mkdir dir="${libdir}"/>

    <fail unless="OBFUSCATE_JAR">missing environment variable OBFUSCATE_JAR from ant.properties</fail>

      <!-- Decide whether to OBFUSCATE  the sims jar file-->
      <condition property="obfuscate">
       <not><or>
        <equals arg1="${OBFUSCATE_JAR}" arg2="NO"/>
        <equals arg1="${OBFUSCATE_JAR}" arg2="No"/>
        <equals arg1="${OBFUSCATE_JAR}" arg2="no"/>
        <equals arg1="${OBFUSCATE_JAR}" arg2="False"/>
        <equals arg1="${OBFUSCATE_JAR}" arg2="FALSE"/>
       </or></not>
      </condition>

    <copy todir="${libdir}">
      <fileset dir="extra">
         <include name="com.ibm.mq.jar"/>
         <include name="com.ibm.mqjms.jar"/>
         <include name="elandjavadev-v2.1.008.jar"/>
         <include name="jbcl.jar"/>
         <include name="jgl3.1.0.jar"/>
      </fileset>
    </copy>

    <copy todir="${libdir}">
      <fileset dir="${elandlibs}">
         <include name="xmlrpc-1.1.jar"/>
         <include name="xercesImpl-2.4.jar"/>
         <include name="xml-apis-2.4.jar"/>
         <include name="xmlParserAPIs-2.4.jar"/>
         <include name="elandsdk-1.0.3.jar"/>
         <include name="rwos-v2.4.0.001_int-javaapi.jar"/>
         <include name="log4j-1.2.8.jar"/>
         <include name="oro-2.0.8.jar" />
         <include name="dom4j-1.3.jar" />
            <include name="castor-0.9.5.3-xml.jar"/>
            <include name="jta1.0.1.jar"/>
            <include name="xercesImpl-2.4.jar"/>
      </fileset>
    </copy>

      <path id="castor.classpath">
         <fileset dir="${elandlibs}">
            <include name="castor-0.9.5.3-xml.jar"/>
            <include name="jta1.0.1.jar"/>
            <include name="xercesImpl-2.4.jar"/>
         </fileset>
      </path>


  </target>

  <target name="installer" depends="CustomerDist">
     <copy todir="install">
         <fileset dir="${dist}"/>
     </copy>
     <ant antfile="build.xml" dir="install" target="installer"/>
  </target>

   <target name="refresh_config_beans" depends="init,cleancastorfiles">
       <property name="target_schema" value="RunwaySimulatorConfig.xsd" />
       <echo>Generating code for XSD Schema: ${target_schema}</echo>
      <copy file="RunwaySimulatorConfig.xsd" tofile="src/RunwaySimulatorConfig.xsd"/>
       <java classname="org.exolab.castor.builder.SourceGenerator"
        fork="yes" dir="${src}" classpathref="castor.classpath">
      <arg line="-i ${target_schema} -f -dest . -nomarshall -package com.elandtech.sims.config.castor"/>
       </java>
       <delete file="src/RunwaySimulatorConfig.xsd"/>
   </target>
   <target name="cleancastorfiles" depends="init">
      <delete dir="${src}/com/elandtech/sims/config/castor"/>
   	<echo>Deleting the directory: ${src}/com/elandtech/sims/config/castor}</echo>
   </target>


  <target name="compile" depends="init,refresh_config_beans" description="compile the source " >

    <copy todir="${build}">
      <fileset dir="src" includes="**/*.jpg"/>
    </copy>

    <javac srcdir="${src}" destdir="${build}" debug="on" optimize="on" deprecation="off">
      <classpath>
        <fileset dir="${libdir}">
          <include name="**/*.jar" />
        </fileset>
        <pathelement path="${build}" />
      </classpath>
    </javac>

    <copy todir="${build}">
      <fileset dir="src" includes="**/*.properties"/>
    </copy>

    <copy todir="${build}">
      <fileset dir="src" includes="**/*.gif"/>
    </copy>

    <copy todir="${build}">
      <fileset dir="src" includes="**/*.jpg"/>
    </copy>

    <copy todir="${build}">
      <fileset dir="src" includes="**/*.txt"/>
    </copy>

    <copy todir="${build}">
      <fileset dir="src" includes="**/*.ghost"/>
    </copy>

    <copy todir="${build}">
      <fileset dir="src" includes="**/*.dec"/>
    </copy>

    <copy todir="${build}">
      <fileset dir="src" includes="**/*.nan"/>
    </copy>

  </target>

  <target name="jar" depends="compile" description="generate JAR file" >

    <mkdir dir="${dist}/lib"/>

    <copy todir="${dist}/lib">
      <fileset dir="${libdir}"/>
    </copy>

    <jar destfile="${dist}/lib/sims.jar"  manifest="jars/sims.mf" >
       <fileset dir="${build}">
           <exclude name="**/itc/**"/>
           <exclude name="**/ghostengines/ITCGhostEngine.class"/>
           <exclude name="**/ghostengines/runway/**"/>
           <exclude name="**/ghostengines/RunwayGhostEngine.class"/>
       </fileset>
    </jar>

    <jar destfile="${dist}/lib/GhostEngineRunway.jar"
       basedir="${build}"
       excludes="*"
       includes="**/ghostengines/runway/** **/ghostengines/RunwayGhostEngine.class **/ghostengines/RequestResponsePair.class" />

    <jar destfile="${dist}/lib/GhostEngineRunway.jar"
       basedir="${build}"
       excludes="*"
       includes="**/ghostengines/runway/** **/ghostengines/RunwayGhostEngine.class" />

    <jar destfile="${dist}/lib/GhostEngineITC.jar"
       basedir="${build}"
       excludes="*"
       includes="**/itc/** **/ghostengines/ITCGhostEngine.class" />

    <!-- <echo>Obfuscate avoidance set to ${localenv.OBFUSCATE}</echo> -->
    <echo>Obfuscate avoidance set to ${OBFUSCATE_JAR}</echo>

  </target>

  <target name="obfuscate" depends="jar" description="obfuscate code" if="obfuscate" >
    <move file="${dist}/lib/sims.jar" tofile="${dist}/lib/sims_unobf.jar"/>

  <taskdef resource="proguard/ant/task.properties"
           classpath="builder/proguard.jar" />

   <proguard ignorewarnings="on" >
        -injars       ${dist}/lib/sims_unobf.jar
        -outjars      ${dist}/lib/sims.jar
        -libraryjars  ${java.home}/lib/rt.jar
        -printmapping progaurd_mapping.txt


        -keep public class com.elandtech.sims.Main {
            public static void main(java.lang.String[]);
        }

        -dontshrink
        -dontoptimize

        -renamesourcefileattribute SourceFile
        -keepattributes InnerClasses,SourceFile,LineNumberTable,Deprecated,Signature,*Annotation*,EnclosingMethod




        <!-- Ghost Engine Classes.. -->
        -keep public class com.elandtech.sims.ghostengines.GhostEngine
        -keep public class com.elandtech.sims.ghostengines.GhostEngine  {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.SimsWithPaternMatchingGhostEngine
        -keep public class com.elandtech.sims.ghostengines.SimsWithPaternMatchingGhostEngine {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.SimsGhostEngine
        -keep public class com.elandtech.sims.ghostengines.SimsGhostEngine {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.RequestResponsePair
        -keep public class com.elandtech.sims.ghostengines.RequestResponsePair {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.ITCGhostEngine
        -keep public class com.elandtech.sims.ghostengines.ITCGhostEngine {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.RunwayGhostEngine
        -keep public class com.elandtech.sims.ghostengines.RunwayGhostEngine {
            public protected *;
        }

        <!-- Logging interface.. -->
        -keep public class com.elandtech.sims.logging.LogManager
        -keep public class com.elandtech.sims.logging.LogManager {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.LogMessage
        -keep public class com.elandtech.sims.logging.LogMessage {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.LogGenerator
        -keep public class com.elandtech.sims.logging.LogGenerator {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.Log4jLogger {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.LogListener. {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.FileLogger {
            public protected *;
        }


        <!-- Remote interface.. -->
        -keep public class com.elandtech.sims.api.Handler
    	-keep public class com.elandtech.sims.api.Handler {
    		public protected *;
		}
        -keep public class com.elandtech.sims.api.RemoteClient
		-keep public class com.elandtech.sims.api.RemoteClient {
			public protected *;
		}

        <!-- Configuration classes.. -->
        -keep public class com.elandtech.sims.config.SimsSettings
        -keep public class com.elandtech.sims.config.ConnectionSettings
        -keep public class com.elandtech.sims.config.SimsSettings {
            public protected *;
        }
        -keep public class com.elandtech.sims.config.ConnectionSettings
        -keep public class com.elandtech.sims.config.ConnectionSettings {
            public protected *;
        }

        <!-- Utility classes.. -->
        -keep public class com.elandtech.eland.commonx.text.EString {
            public protected *;
        }



    </proguard>

    <delete file="${dist}/lib/sims_unobf.jar"/>
  </target>

  <!-- Create a Customer distribution. -->
  <target name="CustomerDist" depends="jar, obfuscate, readversion" description="generate the distribution" >

   <copy file="scripts/startup.bat" tofile="${dist}/startup.bat"/>

    <mkdir dir="${dist}/docs"/>
    <copy todir="${dist}/docs">
      <fileset dir="docs" includes="**/*.pdf"/>
    </copy>

    <copy file="RunwaySimulatorConfig.xsd" tofile="${dist}/docs/RunwaySimulatorConfig.xsd"/>

    <copy todir="${dist}">
      <fileset dir="configdist"/>
    </copy>

    <zip zipfile="RunwayHostsSimCustDist${version}.zip">
      <fileset dir="${dist}"/>
    </zip>
  </target>

  <target name="clean" description="clean up" >
    <delete dir="${testbuild}"/>
    <delete dir="${junitreports}"/>
    <delete dir="${build}"/>
    <delete dir="build2"/>
    <delete dir="${dist}"/>
    <delete dir="${libdir}"/>
    <delete dir="distInternal"/>
    <delete dir="tmp"/>
    <delete>
       <fileset dir="." includes="sims-**.zip"/>
    </delete>
  </target>


  <taskdef name="genjar" classname="org.apache.tools.ant.taskdefs.optional.genjar.GenJar" classpath="builder/GenJar.jar"/>

  <path id="classpath">
     <fileset dir="${libdir}">
         <include name="**/*.jar"/>
     </fileset>
  </path>

    <path id="classpath.sims">
        <pathelement location="${build}"/>
        <fileset dir="${libdir}">
            <include name="**/*.jar"/>
        </fileset>
    </path>

    <path id="classpath.build">
       <pathelement location="${build}"/>
    </path>


  <target name="includeAllResources" >
          <unzip dest="build2">
            <patternset>
                <include name="**/*.properties"/>
                <exclude name="**/*.java"/>
                <exclude name="**/*.class"/>
                <include name="**/*.gif" />
                <include name="**/*.jpg" />
            </patternset>
            <fileset dir="extra">
                <include name="**/*.jar"/>
                <include name="**/*.zip"/>
            </fileset>
        </unzip>
  </target>

  <target name="gen-obfuscate"
          depends="jar"
          description="obfuscate the complete jar" if="obfuscate">

   <taskdef resource="proguard/ant/task.properties"
           classpath="builder/proguard.jar" />

   <move file="distInternal/sims.jar" tofile="distInternal/sims_temp.jar"/>

   <proguard>
        -injars       distInternal/sims_temp.jar
        -outjars      distInternal/sims.jar
        -libraryjars  ${java.home}/lib/rt.jar
        -printmapping progaurd_mapping.txt

        -keep public class com.elandtech.sims.Main {
            public static void main(java.lang.String[]);
        }

        -dontshrink
        -dontoptimize

        -renamesourcefileattribute SourceFile
        -keepattributes InnerClasses,SourceFile,LineNumberTable,Deprecated,Signature,*Annotation*,EnclosingMethod

        <!-- Ghost Engine Classes.. -->
        -keep public class com.elandtech.sims.ghostengines.GhostEngine
        -keep public class com.elandtech.sims.ghostengines.GhostEngine  {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.SimsWithPaternMatchingGhostEngine
        -keep public class com.elandtech.sims.ghostengines.SimsWithPaternMatchingGhostEngine {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.SimsGhostEngine
        -keep public class com.elandtech.sims.ghostengines.SimsGhostEngine {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.RequestResponsePair
        -keep public class com.elandtech.sims.ghostengines.RequestResponsePair {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.ITCGhostEngine
        -keep public class com.elandtech.sims.ghostengines.ITCGhostEngine {
            public protected *;
        }

        -keep public class com.elandtech.sims.ghostengines.RunwayGhostEngine
        -keep public class com.elandtech.sims.ghostengines.RunwayGhostEngine {
            public protected *;
        }

        <!-- Logging interface.. -->
        -keep public class com.elandtech.sims.logging.LogManager
        -keep public class com.elandtech.sims.logging.LogManager {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.LogMessage
        -keep public class com.elandtech.sims.logging.LogMessage {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.LogGenerator
        -keep public class com.elandtech.sims.logging.LogGenerator {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.Log4jLogger {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.LogListener. {
            public protected *;
        }
        -keep public class com.elandtech.sims.logging.FileLogger {
            public protected *;
        }


        <!-- Remote interface.. -->
        -keep public class com.elandtech.sims.api.Handler
        -keep public class com.elandtech.sims.api.RemoteClient

        <!-- Configuration classes.. -->
        -keep public class com.elandtech.sims.config.SimsSettings
        -keep public class com.elandtech.sims.config.ConnectionSettings
        -keep public class com.elandtech.sims.config.SimsSettings {
            public protected *;
        }
        -keep public class com.elandtech.sims.config.ConnectionSettings
        -keep public class com.elandtech.sims.config.ConnectionSettings {
            public protected *;
        }

        <!-- Utility classes.. -->
        -keep public class com.elandtech.eland.commonx.text.EString {
            public protected *;
        }

   </proguard>

    <delete file="distInternal/sims_temp.jar"/>
  </target>

  <!-- Create a combined distribution where all the classes and resources are combined in to one file. -->
  <target name="InternalDist"
          depends="readversion,jar,includeAllResources"
          description="Generates all in one Jar file">

    <copy file="${dist}/lib/sims.jar" tofile="distInternal/sims.jar"/>

    <!-- first perform the obfuscate  on the core SIMS product -->
    <antcall target="gen-obfuscate"/>

    <!-- Create a sims.jar file containing all the files required to run the sims-->
    <genjar jarfile="distInternal/sims${version}.jar">

      <class name="com.elandtech.sims.Main"/>
      <class name="com.elandtech.sims.ghostengines.SimsGhostEngine"/>
      <class name="com.elandtech.sims.ghostengines.SimsWithPaternMatchingGhostEngine"/>
      <class name="com.elandtech.sims.ghostengines.RunwayGhostEngine"/>
      <class name="com.elandtech.sims.ghostengines.ITCGhostEngine"/>

      <library jar="${libdir}/castor-0.9.5.3-xml.jar"/>
      <library jar="${libdir}/log4j-1.2.8.jar"/>
      <library jar="distInternal/sims.jar"/>
      <library jar="${libdir}/xmlrpc-1.1.jar"/>
      <library jar="${libdir}/xml-apis-2.4.jar"/>
      <library jar="${libdir}/xercesImpl-2.4.jar"/>

      <resource>
         <fileset dir="${build}">
           <include name="**/*.properties" />
           <include name="**/*.gif" />
           <include name="**/*.jpg" />
         </fileset>
      </resource>

      <resource>
         <fileset dir="${build2}">
           <include name="**/*.properties" />
           <include name="**/*.gif" />
           <include name="**/*.jpg" />
         </fileset>
      </resource>

      <classpath>
          <pathelement location="distInternal/sims.jar"/>
        <pathelement location="build"/>
        <fileset dir="${libdir}">
            <include name="**/*.jar"/>
        </fileset>
      </classpath>

      <manifest template="${src}/META-INF/sims.mf"/>
    </genjar>

    <copyfile src="scripts/startup_dist2.bat" dest="distInternal/startup.bat"/>

    <mkdir dir="distInternal/docs"/>
    <copy todir="distInternal/docs">
      <fileset dir="docs" includes="**/*.pdf"/>
    </copy>
    <copy file="RunwaySimulatorConfig.xsd" tofile="distInternal/docs/RunwaySimulatorConfig.xsd"/>

    <replace file="distInternal/startup.bat" token="${SIMS_FILENAME}" value="sims_${version}.jar"/>

    <copy todir="distInternal">
      <fileset dir="configdist"/>
    </copy>

    <zip zipfile="RunwayHostsSimIntDist${version}.zip">
      <fileset dir="distInternal"/>
    </zip>

    <delete file="distInternal/sims.jar"/>

  </target>


  <!--  ************************************************************
                     Create a jar containing the
                     Ghost Runway Ghost Engine API Only
        ************************************************************ -->
  <target name="genGhostEngine"
          depends="readversion,compile,includeAllResources"
          description="Generates all in one Jar file">

      <!-- -->
    <genjar jarfile="ghostEngine.jar">

      <class name="com.elandtech.sims.ghostengines.sample.TestRunwayGhost"/>

      <!--
      <resource>
         <fileset dir="${build}">
           <include name="**/*.properties" />
           <include name="**/*.gif" />
           <include name="**/*.jpg" />
           <include name="**/*.dec" />
           <include name="**/*.ghost" />
           <include name="**/*.txt" />
         </fileset>
      </resource>
      <resource>
         <fileset dir="${build2}">
           <include name="**/*.properties" />
           <include name="**/*.gif" />
           <include name="**/*.jpg" />
           <include name="**/*.dec" />
           <include name="**/*.ghost" />
           <include name="**/*.txt" />
         </fileset>
      </resource>
      -->

      <classpath refid="classpath.sims" />
      <!--<manifest template="${src}/META-INF/sims.mf"/> -->
    </genjar>

  </target>



  <!-- utility task to get version information and put it in to enviornment variables ${version} and ${cvsversion}-->
  <taskdef name="getversion" classname="com.elandtech.anttasks.GetVersion" classpath="builder/elandAntTasks.jar"/>
  <target name="readversion" >
     <getversion file="${app.version.file}" />
     <echo>Reading version information from file = ${app.version.file}</echo>
     <echo>version = ${version}</echo>
     <echo>cvsversion = ${cvsversion}</echo>
  </target>

  <!--

      These targets are defined in versionbuild.xml

  -->

  <!-- Tag all files using the variable ${cvsversion}  read in from ${app.version.file} -->
   <target name="cvstag" depends="readversion">
     <ant antfile="versionbuild.xml" dir="." target="cvstag"/>
  </target>

  <!-- increment mini version number-->
  <target name="newmini" >
     <ant antfile="versionbuild.xml" dir="." target="newmini"/>
  </target>

  <!-- increment minor version number-->
  <target name="newminor"  >
     <ant antfile="versionbuild.xml" dir="." target="newminor"/>
  </target>

  <!-- increment Major version number-->
  <target name="newmajor" >
     <ant antfile="versionbuild.xml" dir="." target="newmajor"/>
  </target>

  <!-- Turn beta version on-->
  <target name="betaon" >
     <ant antfile="versionbuild.xml" dir="." target="betaon"/>
  </target>

  <!-- Turn beta version off-->
  <target name="betaoff" >
     <ant antfile="versionbuild.xml" dir="." target="betaoff"/>
  </target>


  <!--

      These targets are defined in junitbuild.xml

  -->
  <target name="testall" depends="init,compile" description="Calls testall in junitbuild.xml">
     <ant antfile="junitbuild.xml" dir="." target="testall"/>
  </target>

  <target name="testsubset" depends="init,compile" description="Calls testsubset in junitbuild.xml">
     <ant antfile="junitbuild.xml" dir="." target="testsubset"/>
  </target>


  <target name="coverage" depends="init,compile" description="Calls coverage in junitbuild.xml">
     <ant antfile="junitbuild.xml" dir="." target="testall-coverage"/>
  </target>

</project>
and I get th errors:
BUILD FAILED
C:\myProjects\sims\build.xml:487: The following error occurred while executing this line:
C:\myProjects\sims\build.xml:383: Expecting class path separator ';' before 'Files\Java\jre1.5.0_09/lib/rt.jar' in argument number 1

can anyone help with this please?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 27 2008
Added on Mar 2 2007
3 comments
449 views