Is it possible to rename a Java class with a string of different length?
I am able to rename a compiled java class with any string that has the same length of the previous class name, but when the length is different the .class file stop working and shows an e开发者_如何学Gorror like:
unknown constant tag X
Where X is a number that changes every time I try to run the applet.
Is there a way to rename a compiled java class with a string of different length of the previous name without using an external program? just editing the .class text contents.
I'll go right out and say it - manually editing the .class file is probably not the best idea. I mean, it can't really be that hard to recompile your program. Plus, if you just rename the class inside the original source, then your source will actually match the class file (why not?). And if you don't have the source, I'm sure you find a decent decompiler (just google it - there seems to be a few good ones). This would allow for easier renaming of classes.
However, if you really, really want to directly manipulate your compiled code, you might want to check out the ASM project. I believe it allows you to do what you want (though it seems a little complicated to me, and it would involve creating an external java program, just like you don't want).
If you're still bent on manually altering the .class file, then may I recommend you to The JAVA Virtual Machine Specification (specifically chapter 4), where you can get all the yummy details of .class files.
If anything can do what you want, and nobody other than you understand why you would want to do something like this, the ASM library would be the tool that lets you do it.
精彩评论