可以手动将修改过的类添加到jar文件中,但为了使其变得简单,我想在运行时完成它。
让我们这样说:
JAR_A.jar -包含A.class和B.class JAR_B.jar -包含修改后的B.class版本
我不想用归档管理器手动添加修改后的B.class,而是希望在运行时完成相同的操作。
发布于 2012-08-05 22:21:37
http://www.java2s.com/Code/Java/File-Input-Output/CreateJarfile.htm
FileOutputStream fout = new FileOutputStream("c:/tmp/foo.jar");
JarOutputStream jarOut = new JarOutputStream(fout);
jarOut.putNextEntry(new ZipEntry("com/foo/")); // Folders must end with "/".
jarOut.putNextEntry(new ZipEntry("com/foo/Foo.class"));
jarOut.write(getBytes("com/foo/Foo.class"));
jarOut.closeEntry();
jarOut.putNextEntry(new ZipEntry("com/foo/Bar.class"));
jarOut.write(getBytes("com/foo/Bar.class"));
jarOut.closeEntry();
jarOut.close();
fout.close();https://stackoverflow.com/questions/11820502
复制相似问题