In my project I had a jar file, now I need to change the code in one of the class in that jar.
I don't have source code version of that jar, was compiled using java 1.5 which uses generics as well.
I need to decompile, recompile and place the new class in that jar, will it work?
Please suggest me the best decompiler which decompiles java 1.5 class files.
I hate to say it, but when you decompile a class file you're not going to get the exact source file. Comments don't exist in class files. Parameter and local variable names are not stored in class files. And worst of all, because of type erasure, generic information does not exist in class files.
Most of the better-known decompilers (like JODE and jad) weren't updated to handle generics. JD-GUI handles them to some degree, but not perfectly. Just give it a try, YMMV.
Rob Spoor wrote:And worst of all, because of type erasure, generic information does not exist in class files.
Not quite - the information is in the class file, it's just not used at runtime by the JVM. But a decompiler can get at that information.
Really? Interesting. I guess the JAD version I'm using is too outdated then.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
Yep, jad was never updated to deal with generics. JODE wasn't either (publicly), but I was successful in enhancing it to make use of a fair amount of the available information to create source files that have more of the Java 5 stuff.
Uday Shankar Mareedu
Greenhorn
Joined: Jun 30, 2012
Posts: 3
posted
0
I had tried with JD-GUI, JAD, DJ but no luck.
I am getting exception hierarchy errors and type cast errors for collections.
Please help me out to resolve this, it is very important for me to move further.
Before you continue, are you sure you're even allowed to modify the classes inside the JAR file? If it's a third party library JAR file and it's been released under some non open source license, decompiling the classes and modifying their contents may be illegal. If it's a JAR file created by the company you work for, the code should still be available. Of course it doesn't have to be unfortunately...
Second: Further to what Rob said, even if you are allowed to do it, I'd be very leery of any "solution" based on a decompilation. Reverse-engineering is tricky stuff. I hope you've run it by your boss AND told him about all the possible downsides.
Winston
Isn't it funny how there's always time and money enough to do it WRONG?
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.