首页 > 代码库 > ant打包和jar包混淆

ant打包和jar包混淆

Ant是一种基于Java的build工具。相似于c语言中的makefile,这里做一记录。方便后面查看。

<?xml version="1.0" encoding="UTF-8"?>  
<project name="vailidategame" default="yguard" basedir=".">  
    <property name="src" value="http://www.mamicode.com/${basedir}/src" />  
    <property name="lib" value="http://www.mamicode.com/${basedir}/lib" /> 
    <property name="build" value="http://www.mamicode.com/${basedir}/build" />  
    <property name="build.class" value="http://www.mamicode.com/${build}/classes" />
	<property name="app.name" value="http://www.mamicode.com/FrameWork" />  
    <property name="app.jar" value="http://www.mamicode.com/${app.name}.jar" /> 
    <property name="obfuscationlog" value="http://www.mamicode.com/${build}"/>
    <property name="obf.jar" value="http://www.mamicode.com/${app.name}_obf.jar" />
    <property name="obfjarpath" value="http://www.mamicode.com/${basedir}/lib"/>
    <property name="shrinklog" value="http://www.mamicode.com/${project_name}_shrinklog.xml"/>
    <property name="renamelog" value="http://www.mamicode.com/${project_name}_renamelog.xml"/>
    <!--请将以下的路径改为你本地的路径-->  
    <property name="webserver" value="http://www.mamicode.com/D:/build-tomcat/webapps" /> 
      
    <!--定义CLASSPACH,编译时用到你外部增加的包-->  
   <!--  <path id="classpath">  
        <pathelement location="${src}" /> 
        <fileset dir="${lib}" includes="***.jar" />  
    </path> -->
    
    <!--删除任务-->  
    <target name="clean" description="删除">  
        <echo message="删除文件夹" />  
        <delete dir="${build}" />  
    </target>  
  
    <!--创建一个暂时文件夹-->  
    <target name="init" description="创建文件夹" depends="clean">  
        <echo message="创建文件夹--以运行" />  
        <mkdir dir="${build.class}" />  
    </target>  
  
    <!-- 编译 -->
    <target name="compile" description="開始编译" depends="init">
           <echo message="生成jar開始……" />  
    	   <javac srcdir="src" destdir="${build.class}">
		    	 <!-- <classpath> 
		             <fileset dir="lib"> 
		                 <include name="**/*.jar"/> 
		             </fileset>
		         </classpath>  -->
		   </javac>  
    </target>
    <!-- 打成jar包 -->
    <target name="generjar" description="打包" depends="compile">
         <echo message="打成jar包"/>
          <jar jarfile="${build}/${app.jar}" basedir="${build.class}">
			<!-- <manifest>
	   			<attribute name="Main-Class" value="http://www.mamicode.com/bean.ant.TestAnt" />
			</manifest> -->
	   	  </jar>
    </target>
    
    <!-- 混淆任务 -->
   <!--  <target name="yguard" depends="generjar">
       <echo message="開始混淆"/>
       <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="yguard.jar" />
       <echo message="产生混淆文件"/>
       <yguard>
           <inoutpair in="${build}/${app.jar}" out="${build}/${obf.jar}"/>
       </yguard>
    </target> -->
   
    <target depends="generjar" name="yguard">
      <taskdef name="yguard" classname="com.yworks.yguard.YGuardTask"
      classpath="yguard.jar"/>
      <!-- the following can be adjusted to your needs -->
      <yguard>
        <inoutpair in="${build}/${app.jar}" out="${build}/${obf.jar}"/>
        <shrink logfile="${shrinklog}">
          <keep>
            <class classes="protected"
            methods="protected" fields="protected">
              <patternset>
                <include name="com.subao.validate.**.*"/>
                <!-- <exclude name="com.subao.validate.http.**.*"/> -->
              </patternset>
            </class>
          </keep>
        </shrink>
        <rename logfile="${renamelog}">
          <property name="error-checking" value="http://www.mamicode.com/pedantic"/>
          <keep>
            <class classes="protected"
            methods="protected" fields="protected">
              <patternset>
                <include name="com.subao.validate.**.*"/>
                <!-- <exclude name="com.subao.validate.http.**.*"/> -->
                <exclude name="com.subao.validate.entity.**.*"/>
              </patternset>
            </class>
          </keep>
        </rename>
      </yguard>
    </target>
</project>  
大概解释一下:

1、上面project标签中的default代表默认运行的入口, basedir代表基准路径。

2、property标签定义变量。

3、target标签中就各自是对应的操作。

相关资源:

yguard混淆:http://download.csdn.net/detail/lxq_xsyu/8149559

jar包混淆工具:http://download.csdn.net/detail/lxq_xsyu/8149539

jar包反编译工具:http://download.csdn.net/detail/lxq_xsyu/8149513
这些工具用起来都特别简单,相关界面截图例如以下:

技术分享


技术分享


ant打包和jar包混淆