ANT - 我怎么不能将文件移动到JAR

时间:2014-03-24 12:02:01

标签: java ant

我已经编辑了我的ANT构建过程。这是我的工作清单:

  • 创建src文件夹的副本和自写AntTask混淆所有字符串
  • ANT使用<jar>
  • 创建一个JAR
  • JAR将由ProGuard
  • 进行模糊处理
  • 必须将其他文件复制到JAR
  • JAR将签署

bodled 步骤是我的问题。我如何将单个文件复制到JAR的根目录。我必须在这里迈出这一步!在赢得工作之前或之后:之前:ProGuard将尝试对此文件进行模糊处理并提供例外。无法工作后,必须对文件进行签名。

任何人都有一个聪明的主意吗?

这是我的ANT构建脚本的缩小版本:

<?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>

2 个答案:

答案 0 :(得分:1)

这是我的ant构建文件的一部分,包括所有xml,jpg,gif和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>

要仅包含一个文件,只需将全名放在include name= "fullnamehere" />

对不起......我们没有看到你加入...... 试试这样:

include name= "builds/temp/_XA.class" />

答案 1 :(得分:0)

由于Jar实际上是一个Zip文件,你可以在proguard完成它之后将jar解压缩到临时目录,在那个临时目录中添加你想要的_XA.class文件,然后重新创建jar文件签名。