maven 学习笔记(四)-创建简单的eclipse+maven工程(简单的java项目打包为jar并混淆jar文件)

    1、按前面例子创建一个简单的java项目

     2、创建项目后,项目结构如下图:

   maven 学习笔记(四)-创建简单的eclipse+maven工程(简单的java项目打包为jar并混淆jar文件)_第1张图片

     2、pom.xml文件配置内容如下:




 

   4.0.0

	com.special.test

	simple-test4

	0.0.1-SNAPSHOT

	simple-test4 - Application

	jar



	

		

			org.apache.commons

			lang

			2.4

		


	


	

		simple-demo4

		UTF-8

	


	

		${project.artifactId}-${project.version}

		src/main/java

		

			

				${basedir}/src/main/java

				

					**/*.java

				

			

		


		

			

				maven-compiler-plugin

				3.1

				

					

						compile

					

				

				

					1.6

					1.6

					${project.build.sourceEncoding}

				

			


			

				maven-source-plugin

				2.1

				

					

					true

					${project.build.sourceEncoding}

				

				

					

						compile

						

							jar

						

					

				

			


			

			

				maven-clean-plugin

				2.4.1

				

					

						

							${project.build.directory}

						

					

				

			


			

				org.apache.maven.plugins

				maven-jar-plugin

				2.3.1

				

					

						

						false

						

							${basedir}/src/main/META-INF/MANIFEST.MF

						

						

							

						

					

				

			


		

	



	


		

		

			proguard

			

				true

			


			

				false

				true

			

			

				


				

					

						com.pyx4me

						proguard-maven-plugin

						2.0.4-SONATYPE

						

							

								package

								

									proguard

								

							

						

						

							${project.build.obfuscate}

							${basedir}/proguard-project.txt

							${project.build.release}


							

								

							


						

					

				

			

		



		

			

			release

			

				false

			

			

				false

				true

			

			

				

				

				

			

		

	







   5、混淆文件配置:proguard-project.txt文件配置内容如下:

# To enable ProGuard in your project, edit project.properties
# to define the proguard.config property as described in that file.
#
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in ${sdk.dir}/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the ProGuard
# include property in project.properties.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}


#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
# ----------------------------------  
#  通过指定数量的优化能执行  
#  -optimizationpasses n  
# ---------------------------------- 
-optimizationpasses 5
#确定统一的混淆类的成员名称来增加混淆 
-useuniqueclassmembernames

#优化时允许访问并修改有修饰符的类和类的成员   
-allowaccessmodification 


#不优化泛型和反射
-keepattributes Signature
-keepattributes *Annotation*
-renamesourcefileattribute SourceFile
-adaptresourcefilenames **.properties
-adaptresourcefilecontents **.properties,META-INF/MANIFEST.MF,META-INF/LICENSE.txt,META-INF/NOTICE.txt

# ----------------------------------  
#   混淆时不会产生形形色色的类名   
#   -dontusemixedcaseclassnames  
# ---------------------------------- 
-dontusemixedcaseclassnames
#      指定不去忽略非公共的库类  
#  -dontskipnonpubliclibraryclasses  
# ---------------------------------- 
-dontskipnonpubliclibraryclasses
# ----------------------------------  
#       不预校验  
#    -dontpreverify  
# ----------------------------------  
-dontpreverify
 #这1句是屏蔽警告,脚本中把这行注释去掉
-ignorewarnings
# ----------------------------------  
#      输出生成信息  
#       -verbose  
# ----------------------------------  
-verbose  
  
#混淆时应用侵入式重载   
-overloadaggressively   
   
#优化时允许访问并修改有修饰符的类和类的成员   
-allowaccessmodification  
#确定统一的混淆类的成员名称来增加混淆   
-useuniqueclassmembernames  

#优化
#-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*


-keep public class * extends android.app.Activity
-keep public class * extends android.app.Application
-keep public class * extends android.app.Service
-keep public class * extends android.content.BroadcastReceiver
-keep public class * extends android.content.ContentProvider
-keep public class * extends android.app.backup.BackupAgentHelper
-keep public class * extends android.preference.Preference
-keep public class com.android.vending.licensing.ILicensingService
-keep class com.tencent.mm.sdk.openapi.WXMediaMessage {*;}
-keep class com.tencent.mm.sdk.openapi.** implements com.tencent.mm.sdk.openapi.WXMediaMessage$IMediaObject {*;}

#第三分库不混淆
-keep class android.support.v4.** {*;}
-keep class org.apache.http.entity.mime.** {*;}

#使用 gson 需要的配置
-keep class com.google.gson.JsonObject { *; }


#-dontwarn org.apache.commons.validator.**


-keepclasseswithmembers class * {
    public (android.content.Context,android.util.AttributeSet);
}

-keepclasseswithmembers class * {
    public (android.content.Context,android.util.AttributeSet,int);
}

-keepclassmembers class * extends android.app.Activity {
    public void *(android.view.View);
}

-keep class * extends android.os.Parcelable {
    public static final android.os.Parcelable$Creator *;
}

# Keep - Library. Keep all public  classes, fields, and methods.
-keep public class * {
    public ;
    public  ;
}
# Keep - Library. Keep all public and protected classes, fields, and methods.
#-keep public class * {
#   public protected ;
#    public protected ;
#}

# Also keep - Enumerations. Keep the special static methods that are required in
# enumeration classes.
-keepclassmembers enum  * {
    public static **[] values();
    public static ** valueOf(java.lang.String);
}

# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,allowshrinking class * {
    native ;
}



#加载依赖库
-libraryjars libs/commons-lang-2.4.jar
#-libraryjars libs/commons-validator-1.4.0.jar


你可能感兴趣的:(maven)