0

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>
Adrian Preuss
  • 3,228
  • 1
  • 23
  • 43

2 Answers2

1

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

LostKatana
  • 468
  • 9
  • 22
  • try with many options on `javac` or `jar` but that won't work: `javac doesn't support the nested "copy" element.` EDIT: Wait, found an logical error :) – Adrian Preuss Mar 24 '14 at 12:42
  • Hey, it works :D Only ProGuard had yet an problem. the _XA.class is not an Java class. Its an encrypted Textfile. – Adrian Preuss Mar 24 '14 at 12:48
  • No problem. But that is the problem with proguard. I cant say to that "dont touch the `_XA.class`". I need to add these After the obfuscating process – Adrian Preuss Mar 24 '14 at 12:53
  • I think this needs a new post as no one will look for ProGuard error in this topic – LostKatana Mar 24 '14 at 12:55
  • Oh okay...missunderstood it a bit. But you could edit your post and show us your error. But I'm out for not knowing ProGuard. Good luck on that. – LostKatana Mar 24 '14 at 12:58
  • I've done some search in stackoverflow and found [>this](http://stackoverflow.com/questions/4830474/how-to-keep-exclude-a-particular-package-path-when-using-proguard). Maybe you can ignore the file somehow in that way. – LostKatana Mar 24 '14 at 13:11
  • No i can't. It's **not an Java class**! Had **no** class and **no** methods ;) – Adrian Preuss Mar 24 '14 at 13:19
  • positive feedback. *.class files works only with original class files from java. I have rename that to _XA.bin. I think its the easiest way :) – Adrian Preuss Mar 24 '14 at 13:22
0

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.

David
  • 2,602
  • 1
  • 18
  • 32