I have a Java based TCP Client that talks to our production server, which I'm re-writing. The client has the server's IP & port hard coded. What I want to be able to do is change just the IP address in the client to 127.0.0.1 & I can use the same port number on my dev box. Here's the rub, I don't have all the source code, so I can't just recompile it. The guy who wrote it hasn't worked here for about four years and while I have his hard drive, I haven't been able to find a compiled loop back client (even though I found partial source code for it) or even all the source code for the production client. I suspect he wrote his code on a network drive and it's been lost through the intervening years.
Is there some way for me to decompile the client and recompile with that change? Hex or binary edit (I have no skill at either, I've just seen it done)? Maybe WinRAR since my understanding is that .jar files are just zipped files? Or, is there some way I could trap the outgoing TCP traffic from the client & re-route it to my dev box? I can't take down the production server to test, and without a modified client it's going to be difficult to ensure I'm emulating the production server responses to the client.
I found this SO article: Decompile & recompile single file from jar, however I don't understand the difference between disassembly & decompiling, but I have found the utility JD mentioned there.
The java decompiler you found (http://java.decompiler.free.fr/) will take the compiled jar file you have and create java source files. You will then have to edit the source files to make the changes you want and recompile.
I would suggest making the host and port configurable via the command line to avoid this issue again.
Copy the jar to system into your workstation and unzip it . Then use a tool like jad to decompile the class you are looking for and make the changes. you should be able to compile it as the jars you need for compilation are the same jars you would need to run your client
来源:https://stackoverflow.com/questions/15144539/change-jar-file-without-the-source