How do you recompile a jar file?

二次信任 提交于 2019-11-29 20:05:44

问题


I took an old jar file and edited it. Now i have a folder that has all the files and I want to recompile them back to a jar file. How do i do this?


回答1:


Jar files aren't "compiled" in the normal sense of the word. But you just create one with the jar command:

jar cvf myfile.jar file1 file2 etc

You can use globbing as normal:

jar cvf ../myfile.jar *

Run jar -? or read the docs for more information.

Note that for an executable jar file, you'll need to specify the manifest file as well.




回答2:


How did you edit it?

Anyway, jar files follow the same format as regular zip files. If you want to update the content of the jar ( probably with a new file ) you could do:

jar -uf yourJar.jar  path/to/updated/Class.class 

That would update your jar with the file path/to/updated/Class.class If there's already a class with that name in that path, it would be replaced. If is not it would be created.

After this your jar is up to date.




回答3:


Jar files usually contain compiled java files (class-files) and resources. If you are allowed to make changes on this jar, you could disassemble the class files using JAD and after recompilation assemble them again with the command jar

How did you edit a jar file, hex editor?




回答4:


A jar file is just a zip file with a few extra files. You Can use any zip utility to rejar an unjarred jar file.



来源:https://stackoverflow.com/questions/3350545/how-do-you-recompile-a-jar-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!