`
z610
  • 浏览: 39237 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Make new jar from a existing jar

    博客分类:
  • java
阅读更多

import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;

public class Test {

String destPath = "D:\\tmp\\b.jar";
String sourcePath = "D:\\tmp\\a.jar";

/**
* @param args
*/
public static void main(String[] args) {

Test test = new Test();
try {
test.run();
} catch (IOException e) {
e.printStackTrace();
}
}

public void run() throws IOException {
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION,"1.0");
JarOutputStream target = new JarOutputStream(new FileOutputStream(destPath), manifest);
add(target);
target.close();
}

private void add(JarOutputStream target) throws IOException {
BufferedInputStream in = null;
try {
JarFile jarFile = new JarFile(sourcePath);

Enumeration<JarEntry> enu = jarFile.entries();

while (enu.hasMoreElements()) {
JarEntry oneEntry = enu.nextElement();
JarEntry entry = new JarEntry(oneEntry);
if (entry.getName().equalsIgnoreCase("META-INF/MANIFEST.MF")) {
continue;
}
target.putNextEntry(entry);
in = new BufferedInputStream(jarFile.getInputStream(oneEntry));

byte[] buffer = new byte[1024];
while (true) {
int count = in.read(buffer);
if (count == -1)
break;
target.write(buffer, 0, count);
}
target.closeEntry();
}

} finally {
if (in != null)
in.close();
}
}

}

 

分享到:
评论

相关推荐

    apktool documentation

    -m / --match-original is a new feature for apk analysis. This retains the apk is nearly original format, but will make rebuild more than likely not work due to ignoring the changes that newer aapt ...

    tomcat-8_API

    * catalina-storeconfig.jar (Generation of XML configuration from current state) * catalina-tribes.jar (Group communication) * ecj-4.4.jar (Eclipse JDT Java compiler) * el-api.jar (EL 3.0 API) * jasper...

    tomcat-7_API_帮助文档

    resolve bugs and/or add new features. No existing interface will be removed or changed although it may be deprecated. - org/apache/catalina/* - org/apache/catalina/comet/* Note: As Tomcat 7 matures, ...

    UE(官方下载)

    The benefit of a column maker is that it can help you to format your text/code, or in some cases to make it easier to read in complex nested logic. Quick Open UltraEdit and UEStudio provide multiple ...

    ubuntu11.10(64位)虚拟linux系统下 ---修改编译android工程

    然后在Eclipse中通过File &gt; New &gt; Android Project,选择"Create project from existing source",指定项目名称为Settings,并设置源代码目录为/home/xxx/Settings。 由于导入的项目缺少依赖库,会出现错误。解决这...

    hive-playN:使用 playN 的 hive-core GUI

    蜂巢游戏N hive-core ( ) 的基于 playN ( ) GUI 实现。 目标是创建一个可用于与他人在线玩的功能性 gui,主要用于调试您自己的 AI(机器人)。...y - Change view theme (cycling between existing)

    可以在eclipse下调试android的源Launcher

    在Eclipse中,创建一个新的Android项目,选择"Import existing Android code into workspace",然后指向`frameworks\base\packages\Launchers`目录。注意,由于我们是导入源码而不是普通的Android项目,所以可能需要...

    将Android原生的Phone程序通过eclipse跑在模拟器上

    - 选择`from existing code`选项,设置工程名为`Phone2`。 - `Location`选择`~/workspace/Phone`。 - `Target Build`选择刚刚编译好的SDK。 - 点击`Finish`完成创建。 #### 步骤五:解决源码中的错误 1. **...

    eclipse基于ant自动化打包

    Ant是Apache软件基金会的一个项目,它是一个基于Java的构建工具,类似于Make,但设计更加面向Java开发者。Ant使用XML来描述构建过程,包括编译、测试、打包等任务。 在标题"eclipse基于ant自动化打包"中,我们关注...

    hfdp-strategy:头先设计模式

    Eclipse的“File” -&gt; “Import” -&gt; “Existing Projects into Workspace”选项可以轻松完成导入。 对于命令行用户,项目通常包含一个Makefile,这是一个自动化脚本,用于编译和构建项目。用户只需按照Makefile的...

Global site tag (gtag.js) - Google Analytics