如何从war文件中获取java源代码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30984696/
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
how to get java source code from war file?
提问by Karthik
I do not have the latest source code but have the war(up to date) file deployed on server.
我没有最新的源代码,但在服务器上部署了战争(最新)文件。
Please suggest the best ways to
1) Retrieve source code from war/ear
2) Compare & Merge/update the available source code with the code present in war/ear but missing in available source code(I am using ECLIPSE IDE)
请建议最好的方法
1) 从 war/ear 中检索源代码
2) 将可用源代码与 war/ear 中存在但可用源代码中缺少的代码进行比较和合并/更新(我正在使用 ECLIPSE IDE)
Thanks in advance
提前致谢
采纳答案by zeisi
War files are basically zip files, so they are easy to extract. (using unzip or just renaming the file) Next you could use a Java decompiler like JD. But you won't get the original Java code as the compiler does a lot of optimization. But it should give you a good starting point
War 文件基本上是 zip 文件,因此很容易提取。(使用解压缩或只是重命名文件)接下来你可以使用像 JD 这样的 Java 反编译器。但是你不会得到原始的 Java 代码,因为编译器做了很多优化。但它应该给你一个很好的起点
回答by Kevin Hooke
Once you've extracted the classes from the EAR/WAR/Jars, use JAD to decompile the code you're interested in to get back to the source: http://varaneckas.com/jad/
从 EAR/WAR/Jars 中提取类后,使用 JAD 反编译您感兴趣的代码以返回源代码:http: //varaneckas.com/jad/
I'm not sure there's any out-of-the-box tool that is going to compare/diff your original source with the decompiled source produced from something like JAD though. Also bear in mind, decompiling classes back to source is not going to produce source that looks identical to the original source - code style is going to be different, maybe even some structure of the code. It's going to be difficult to do a diff between the original source and decompiled source.
我不确定是否有任何开箱即用的工具可以将您的原始源代码与从 JAD 之类的东西生成的反编译源代码进行比较/差异。还要记住,将类反编译回源代码不会产生与原始源代码看起来相同的源代码 - 代码风格会有所不同,甚至可能是代码的某些结构。在原始源代码和反编译源代码之间进行差异将很困难。
If you have the original source but not the source for the code that is currently deployed, maybe a better question is to ask 'why not'? If there's something missing in your build process where you are not tracking what source is being used for each build, maybe this is an easier issue to address moving forward, rather than trying to do something clumsy and error prone like a diff between some other source and decompiled source?
如果您有原始源代码,但没有当前部署的代码的源代码,也许更好的问题是问“为什么不”?如果您的构建过程中缺少某些内容,您没有跟踪每个构建使用的源,那么这可能是一个更容易解决的问题,而不是尝试做一些笨拙且容易出错的事情,例如其他源之间的差异和反编译源?
回答by Timo
The exact answer: it is not possible to get the original source code (.java
files) from a war
as opposed to a jar
(java
archive). When you create a jar
file, you can decide if you want to include the .java
files. Only a java decompiler can help, see the other answers.
确切的答案是:不可能.java
从 a 中获取原始源代码(文件),war
而不是 a jar
(java
存档)。创建jar
文件时,您可以决定是否要包含这些.java
文件。只有 java 反编译器可以提供帮助,请参阅其他答案。
回答by user1400290
回答by Arasn
Inside the war folder, under specific module - Based on your project hierarchy (if maven project -these config will be available in Pom.xml - it will define which path and what jar name) you will have the Core JAR files of each module.
在 war 文件夹中,在特定模块下 - 基于您的项目层次结构(如果 maven 项目 - 这些配置将在 Pom.xml 中可用 - 它将定义哪个路径和什么 jar 名称)您将拥有每个模块的核心 JAR 文件。
Open those jar files using any decompiler , you will be able to find the class/java files in it..
使用任何反编译器打开这些 jar 文件,您将能够在其中找到 class/java 文件。