具有播放2.2.3的sbt-proguard [英] sbt-proguard with play 2.2.3

查看:85
本文介绍了具有播放2.2.3的sbt-proguard的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们用play 2.2.3开发了一个Web应用程序,并希望对其进行混淆.我正在尝试使用 sbt-proguard 插件.我将以下行放在 PROJECT_FOLDER/project/plugins.sbt 文件

We developed a web application with play 2.2.3 and want to obfuscate it. I am trying to use sbt-proguard plugin. I put the line below to PROJECT_FOLDER/project/plugins.sbt file

addSbtPlugin("com.typesafe.sbt" % "sbt-proguard" % "0.2.2")

并将下面的行放入 PROJECT_FOLDER/build.sbt 文件

proguardSettings

ProguardKeys.options in Proguard ++= Seq("-dontnote", "-dontwarn", "-ignorewarnings")

ProguardKeys.options in Proguard += ProguardOptions.keepMain("Application")

inConfig(Proguard)(javaOptions in ProguardKeys.proguard := Seq("-Xmx2g"))

当我在播放控制台上说 dist 并在插件网站上说他们叫 proguard:proguard 时,我不确定proguard是否正常工作.当我在Play控制台上写 proguard:proguard 时,Play给我显示了以下错误

I am not sure proguard is working when I say dist on play console and on the plugin website they say call proguard:proguard. When I write proguard:proguard on play console, Play gives me error shown below

[info] Reading program jar [/Users/kamil/DEVELOPMENT/play-2.2.3/repository/local/net.sf.ehcache/ehcache-core/2.6.6/jars/ehcache-core.jar] (filtered)
[info] Reading program jar [/Users/kamil/DEVELOPMENT/play-2.2.3/repository/cache/org.json/json/jars/json-20140107.jar] (filtered)
[info] Reading library jar [/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/jce.jar]
[info] Reading library jar [/Library/Java/JavaVirtualMachines/jdk1.7.0_45.jdk/Contents/Home/jre/lib/rt.jar]
[error] Error: The output jar is empty. Did you specify the proper '-keep' options?
[trace] Stack trace suppressed: run last proguard:proguard for the full output.
[error] (proguard:proguard) Proguard failed with exit code [1]
[error] Total time: 35 s, completed 10.Tem.2014 09:45:23

有人成功使用此插件和play框架吗?

Is there anybody using this plugin with play framework succesfully?

推荐答案

花了几天努力尝试正确配置sbt-proguard之后,我放弃了,在构建项目后才使用proguard.

After burning a few days on trying to make sbt-proguard configured properly, I gave up, and just used proguard after building the project.

我没有将混淆处理作为构建部分包括在内,而是打开了由activator dist生成的zip文件,混淆了jar,然后将其返回到同名的lib文件夹中.这是操作方法:

Instead of including the obfuscation as a build part, I opened the zip file generated by activator dist, obfuscated the jar and returned it back into the lib folder with the same name. Here is how to do it:

Proguard可以独立运行.您只需从 sourceforge 下载tar文件,然后使用配置文件运行jar,,例如:

Proguard can run on its own. You simply download the tar file from sourceforge and run the jar with a configuration file like:

java -jar /path/to/proguard/lib/proguard.jar @CONF_FILE

现在是配置文件,您需要指定:

Now for the configuration file, You need to specify:

  1. 罐子-被混淆的罐子-
    解压缩由dist创建的zip文件后,将其cd到lib文件中,并找到jar名称YOUR_PROJECT.VERSION-sans-externalized.jar,这是您需要混淆的jar.
  2. outjar-混淆的jar(输出)的路径.在该过程结束时,只需将此jar复制回lib目录,然后将其重命名为in jar的名称即可.

  1. injar - the jar being obfuscated -
    After unzipping the zip file created by the dist, cd into the lib file and found the jar names YOUR_PROJECT.VERSION-sans-externalized.jar this is the jar you need to obfuscate.
  2. outjar - the path for the obfuscated jar (output). At the end of the process just copy this jar back to the lib directory and rename it to the name of the in jar.

keep-需要保留其名称的任何程序包名称,类,方法或字段.您应保留在网络应用程序中的常见事项:

keep - any package-name, class, method or field that needs to keep its name. Common things that you should keep in a webapp:

3.1.控制器方法名称.

3.1. controller method names.

3.2.游戏使用的并在application.conf中指定的任何类,例如ErrorHandler,ApplicationLoader

3.2. any class that is used by play and specified in the application.conf like ErrorHandler, ApplicationLoader

3.3.所有路由器生成的类

3.3. All router-generated classes

库-包括lib文件中除您自己的jar以外的所有库.

Libraries - include all libraries in the lib file except for your own jars.

因此,您的conf.pro文件应如下所示:

So your conf.pro file should like something like this:

-injars /path/to/jar/project-version-sans-externalized.jar(!META-INF)
-outjars /path/to/obfuscated/jar.jar


-keepnames class com.example.ErrorHandler
-keepnames class com.example.ApplicationLoader    

-keepnames class controllers.**
-keepclassmembernames class controllers.** {
    <methods>;    
}

-keeppackagenames controllers.**, router.**, views.**
-keep class router.** {*;}
-keepnames class router.** {*;}
-keepclassmembers class router.** {*;}
-keep class views.** {*;}
-keepnames class views.** {*;}
-keepclassmembers class views.** {*;}
-libraryjars /usr/lib/jvm/latest/jre/lib/rt.jar
-libraryjars /path/to/lib/library1.jar
-libraryjars /path/to/lib/library2.jar

完成混淆后,您将输出jar复制回了它的旧目录和名称,您可以压缩您的项目,并且您已经获得了混淆的播放项目!

After obfuscation is done and you copied the output jar back to its old dir and name, you can zip back your project and you've got an obfuscated play project!

我真的建议您查看 proguard手册.它有许多针对不同项目设置和框架的示例.

I really recommend looking at the proguard manual. It has many examples for different project setups and frameworks.

这篇关于具有播放2.2.3的sbt-proguard的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆