Java(Android)修改jar里面的包名并生成新的jar文件
来源:互联网 发布:云计算软件工程师 编辑:程序博客网 时间:2024/06/05 02:25
为了防止冲突,修改包名是最直接的途径。
修改jar里面的包名也比较简单,到官网下载个jarjar.jar(会有多个版本,可以自己选择)
地址:http://code.google.com/p/jarjar/downloads/list
接下来需要的步骤如下:
1.原始的jar包(volley.jar)
2.jarjar.jar包(我下载的是jarjar-1.4.jar)在此目录下(如果提供绝对路径也可以)
3.新建一个规则文件,如:rule.txt
4.在rule.txt添加规则:rule com.android.volley.** com.my.volley.@1
5.运行命令:
java -jar jarjar-1.4.jar process rule.txt volley.jar test.jar
这样,就把volley.jar里面的com.android.volley包名替换为com.my.volley并输出到test.jar
帮助文档入下,提供了帮助描述(如果想了解更多可以到下载地址中下载源码):
Jar Jar Links - A utility to repackage and embed Java libraries
Copyright 2007 Google Inc.
Command-line usage:
java -jar jarjar.jar [help]
Prints this help message.
java -jar jarjar.jar strings <cp>
Dumps all string literals in classpath <cp>. Line numbers will be
included if the classes have debug information.
java -jar jarjar.jar find <level> <cp1> [<cp2>]
Prints dependencies on classpath <cp2> in classpath <cp1>. If <cp2>
is omitted, <cp1> is used for both arguments.
The level argument must be "class" or "jar". The former prints
dependencies between individual classes, while the latter only
prints jar->jar dependencies. A "jar" in this context is actually
any classpath component, which can be a jar file, a zip file, or a
parent directory (see below).
java -jar jarjar.jar process <rulesFile> <inJar> <outJar>
Transform the <inJar> jar file, writing a new jar file to <outJar>.
Any existing file named by <outJar> will be deleted.
The transformation is defined by a set of rules in the file specified
by the rules argument (see below).
Classpath format:
The classpath argument is a colon or semi-colon delimited set
(depending on platform) of directories, jar files, or zip files. See
the following page for more details:
http://java.sun.com/j2se/1.5.0/docs/tooldocs/solaris/classpath.html
Mustang-style wildcards are also supported:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6268383
Rules file format:
The rules file is a text file, one rule per line. Leading and trailing
whitespace is ignored. There are three types of rules:
rule <pattern> <result>
zap <pattern>
keep <pattern>
The standard rule ("rule") is used to rename classes. All references
to the renamed classes will also be updated. If a class name is
matched by more than one rule, only the first one will apply.
<pattern> is a class name with optional wildcards. "**" will
match against any valid class name substring. To match a single
package component (by excluding "." from the match), a single "*" may
be used instead.
<result> is a class name which can optionally reference the
substrings matched by the wildcards. A numbered reference is available
for every "*" or "**" in the <pattern>, starting from left to
right: "@1", "@2", etc. A special "@0" reference contains the entire
matched class name.
The "zap" rule causes any matched class to be removed from the resulting
jar file. All zap rules are processed before renaming rules.
The "keep" rule marks all matched classes as "roots". If any keep
rules are defined all classes which are not reachable from the roots
via dependency analysis are discarded when writing the output
jar. This is the last step in the process, after renaming and zapping.
0 0
- Java(Android)修改jar里面的包名并生成新的jar文件
- 【修改jar】jclasslib修改jar包里面的class文件
- 修改jar包里面的class文件
- 如何修改 jar 文件的包名
- 【Android】如何修改 jar 文件的包名
- Android 编程下如何修改 jar 文件的包名
- Android 编程下如何修改 jar 文件的包名
- Android 编程下如何修改 jar 文件的包名
- 修改jar的包名
- 编译Java文件并生成jar包
- 修改jar里的包名
- Java开发工具_Eclipse中如何生成jar包并导入到新的项目中
- 【转】Android 编程下如何修改 jar 文件的包名
- 如何读取Jar包里面的文件
- 如何读取Jar包里面的文件
- 解决jar包里面的文件冲突
- 运行jar包时读取jar里面的文件
- android 生成jar包里面包含资源文件
- Gradle build error, Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug
- gitQ&A
- JS笔记02-BOM&window
- 【Java每日一题】20170117
- [poj2478] Farey Sequence
- Java(Android)修改jar里面的包名并生成新的jar文件
- [Err] 1075 - Incorrect table definition; there can be only one auto column and it must be defined as
- s:iterator跳出当前循环
- Spring框架的junit测试遇见的问题
- 每天一个 Linux 命令(20):find命令之exec
- My First Blog
- less循环生成类
- 关于接口的多继承的理解
- 好书列表