eclipse 如何在 EAR 文件中编辑 java 类文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6459267/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:29:16  来源:igfitidea点击:

How to edit a java class file in an EAR file

javaeclipseejbear

提问by user812852

I need to edit one line of code in the EJB. I import the ear into eclipse, but I cannot figure out how to edit the .class files. I can view them using Jadclipse, but I cannot edit them. I edited the .class file manually and put the revised .java file in the EJB and tried to export the ear, but it just deleted my .java. I guess my question is really how do I recompile my .java file into my project. I need to import an EAR, edit a .class file and then export it as an EAR. This project was written for the business I am contracted to over 4 years ago. The developer that wrote it is no longer with us. So all I have is the EAR. Any help is appreciated.

我需要在 EJB 中编辑一行代码。我将耳朵导入 eclipse,但我不知道如何编辑 .class 文件。我可以使用 Jadclipse 查看它们,但我无法编辑它们。我手动编辑了 .class 文件并将修改后的 .java 文件放入 EJB 并尝试导出耳朵,但它只是删除了我的 .java。我想我的问题实际上是如何将我的 .java 文件重新编译到我的项目中。我需要导入一个 EAR,编辑一个 .class 文件,然后将它导出为一个 EAR。这个项目是为我 4 年前签约的业务而编写的。编写它的开发人员不再与我们在一起。所以我只有 EAR。任何帮助表示赞赏。

回答by nsfyn55

Get yourself a good hex editor.

给自己找一个好的十六进制编辑器。

回答by Asynkronos

You can try decompiling the class files back into Java using a decompilier tool such as JD:

您可以尝试使用 JD 等反编译工具将类文件反编译回 Java:

http://java.decompiler.free.fr/

http://java.decompiler.free.fr/

Decompiliers are not perfect, however. The code they generate may not always be correct, so use with caution.

然而,反编译器并不完美。它们生成的代码可能并不总是正确的,因此请谨慎使用。

回答by Romain Hippeau

An EAR file is just a zip file. Rename it to .zip and you can view it in WinZip or whatever.
Then if you are lucky you can decompile the file and make any mods you need to the file (I say lucky because it depends how the file was compiled, obfuscated or without any debug info).
Use ANT to rebuild the EAR (See How do I create an EAR file with an ant build including certain files?or some other resource)
You should be good to go, just redeploy the new EAR.

EAR 文件只是一个 zip 文件。将其重命名为 .zip,您可以在 WinZip 或其他任何方式中查看它。
然后,如果幸运的话,您可以反编译该文件并对该文件进行任何修改(我说幸运,因为这取决于文件的编译方式、混淆方式或没有任何调试信息)。
使用 ANT 重建 EAR(请参阅如何使用包含某些文件的 ant 构建创建 EAR 文件?或其他一些资源)
您应该很高兴,只需重新部署新的 EAR。

回答by Robin

You don't edit .class files. It's the .java files that you edit and then compile into the .class files. I am assuming that the .java files must be in there as well if you can view them and update. Of course it is pointless to try to put the .java back in and export since the runtime will require the .class.

您不编辑 .class 文件。它是您编辑然后编译成 .class 文件的 .java 文件。我假设 .java 文件也必须在那里,如果您可以查看和更新​​它们。当然,尝试将 .java 放回并导出是没有意义的,因为运行时将需要 .class。

Of course, if it is EJB code inside an EAR, it is quite possible that it is either generated code, or code that will have to be run through an EJB compiler to produce a proper EJB.

当然,如果它是 EAR 中的 EJB 代码,它很可能是生成的代码,或者必须通过 EJB 编译器运行以生成正确的 EJB 的代码。

回答by Sergii Zagriichuk

You cannot edit class file, but you can try to edit bytecode in runtime, try javassist

你不能编辑类文件,但你可以尝试在运行时编辑字节码,试试javassist