0

I have a large pre-compiled project with lots of packages and class files. I have extracted one of the class files and decompiled it and edited some of the code inside. Now I would like to compile the changed code and re-insert it back into the original pre-compiled project, but unfortunately the code keeps many references to Objects in the pre-compiled project so I cannot compile without having it be already in the project which creates a rather large paradox. is there any for me to do what I am trying to accomplish?

Will Sherwood
  • 1,484
  • 3
  • 14
  • 27

2 Answers2

2

Just compile it with a classpath which refers to the existing class files (or the jar file that contains those class files). There should be no problem.

However, note that if you change any constants in the file, those changes won't be reflected in any other code that refers to those constants.

It would generally be a much better idea to recompile from the complete source code. It would also be a better idea to use the original source code than just the result of decompilation - do you not have access to the original source code? (If you don't, are you sure that what you're doing is even legal in your country? I'm not a lawyer, but you should at least check...)

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • No, I do not have access to the original source code. Fear not, it is for educational purposes only :) – Will Sherwood May 11 '14 at 18:06
  • 1
    @JohnDoe: "educational purposes" doesn't mean something is legal or even necessarily ethical. Think very carefully before proceeding - and also ask yourself whether the original authors would like you to do what you're planning to. If they would, maybe they already make the source code available. If they wouldn't, are you really comfortable going against their wishes? – Jon Skeet May 11 '14 at 18:08
0

I would recompile the whole thing to avoid problems, but if you MUST, try this and let me know if they work for you:

Instead of loading the class on your original project, load it using classForName http://docs.oracle.com/javase/7/docs/api/java/lang/Class.html

Remember that you cannot change the signature of the methods as this would indicate a different object since it wouldn't follow the same contract (interface).

Also keep in mind the serialVersionId What is a serialVersionUID and why should I use it?

Community
  • 1
  • 1
Alexandre Santos
  • 8,170
  • 10
  • 42
  • 64