Is it possible to replace a class file in a compiled Java project?

This may and should be a question that has been asked and answered many times, but I just cannot find the answer.

If I have a compiled application running on a server, can I compile the application on my local computer and replace the class that I compiled on my local computer with what is on the server?

In other words, can I replace a file that was compiled and located on the server side with an almost identical file that was compiled and located on my local machine?

Since the server-side version has some hard-coded connections in other files, and I don’t know all the places, I would prefer only to exchange one file that I need, instead of recompiling for the application as a whole.

+3
source share
3 answers

The answer to your question: yes, you can replace the class file, but it is somewhat complicated, because you must be sure that no other dependencies have changed.

For example, if the class you are compiling involves changing the signatures of the method methods that are used in other classes, you also need to replace them. As long as the signature methods of the public, secure, or standard methods are not changed, you should be fine.

, , , .

public MyObject getObject(MyObject2 mySecondObject)

vs

public MyObject getObject(int a, int b, int c)

, , , , , , .

, , , , , . , , , , , , .

, .

+3

, . , , . .

, . , , .

+2

, "" ( , ).

: Java classpath. /, .

, :

  • ( ) .
  • , .

  • classpath (, script ), .

  • . .

Note: This works for "stand-alone" applications and generally for those who do not bother with custom class loaders (for example, this applies to application servers).

A more complicated solution may be based on defining your classloader, which will look at such a folder (as I described) and try to load resources from there.

Hope this helps.

+1
source

All Articles