简体   繁体   中英

How to edit a java class file in an EAR file

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.

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

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

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

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

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.

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.

您无法编辑类文件,但您可以尝试在运行时编辑字节码,尝试使用javassist

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM