eclipse 修改jar文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2185408/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Modifying a jar file
提问by Andromeda
I have a jar file which is used in html file as applet. I want to modify the content of the jar file and to rebuild the jar file so that the html will work fine with the new jar file. How can i do this??
我有一个 jar 文件,它在 html 文件中用作小程序。我想修改 jar 文件的内容并重建 jar 文件,以便 html 可以与新的 jar 文件一起正常工作。我怎样才能做到这一点??
I already tried unzipping using 7zip nad modified the source and created the new jar. But when i use it in html it shows some java.lang.Classnotfound error
我已经尝试使用 7zip 解压缩 nad 修改源并创建新的 jar。但是当我在 html 中使用它时,它显示了一些 java.lang.Classnotfound 错误
回答by Yada
You can unjar or rejar the classes and source files as you wish.
您可以根据需要解压缩或重新压缩类和源文件。
unjar
解压
jar -xvf abc.jar
jar
罐
jar cf abc.jar input-files
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
回答by Carlos Blanco
Make the changes in the code (.java files), recompile to get the .class files. Then simply replace the old .class files in the jar with the new ones. I usually use WinZip, but you can use whatever app that can handle .Zip files. It should just work.
更改代码(.java 文件),重新编译以获取 .class 文件。然后只需将 jar 中的旧 .class 文件替换为新文件即可。我通常使用 WinZip,但您可以使用任何可以处理 .Zip 文件的应用程序。它应该可以正常工作。
I've faced cases where the launcher of the app uses some sort of verification and checks for this kind of changes. I had to use a new launch script. This doesn't seem to be your case though.
我遇到过应用程序启动器使用某种验证并检查此类更改的情况。我不得不使用新的启动脚本。不过,这似乎不是你的情况。
回答by clwhisk
This is surely possible from the command line. Use the u
option for jar
这肯定可以从命令行进行。使用u
选项jar
From the Java Tutorials:
来自 Java 教程:
jar uf jar-file input-file(s)
"Any files already in the archive having the same pathname as a file being added will be overwritten."
“存档中已有的与添加的文件具有相同路径名的任何文件都将被覆盖。”
请参阅更新 JAR 文件
A brief test shows this quickly updates changes apart from trying to delete the file.
一个简短的测试表明,除了尝试删除文件之外,这还可以快速更新更改。
I haven't seen this answer on other threads about modifying jar files, and many, marked as duplicates, suggest there is no alternative but to remake the jar completely. Please correct if wrong.
我还没有在其他关于修改 jar 文件的线程上看到这个答案,许多标记为重复的,表明除了完全重新制作 jar 之外别无选择。如有错误请指正。
回答by Freiheit
Disclaimer: When reverse engineering any code be sure that you are staying within the limits of the law and adhering to the license of that code.
免责声明:对任何代码进行逆向工程时,请确保您遵守法律的限制并遵守该代码的许可。
Follow the instructions above to unpack the JAR.
按照上面的说明解压 JAR。
Find the original source of the JAR (perhaps its on SourceForge) and download the source, modify the source, and rebuild your own JAR.
找到 JAR 的原始源(可能在 SourceForge 上)并下载源,修改源,然后重建您自己的 JAR。
You can also decompile the class files in the JAR. This is a rather advanced process and has a lot of "gotchas".
您还可以反编译 JAR 中的类文件。这是一个相当高级的过程,有很多“陷阱”。
回答by Nick Veys
JARs are just ZIP files, use whatever utility you like and edit away!
JAR 只是 ZIP 文件,使用您喜欢的任何实用程序并进行编辑!