I modified one class of my application, but I don't want to rebuild the whole now and redeploy the whole application.
I just want to create a new jar which only contains this modified class and only deploy this jar.
So when the application restarts, it will load the new class instead of old one.
Completely unreliable: you should never rely on the new class being picked up first--you do not control the classloader, the classloader might change, etc. Having multiple versions of the same class on the classpath is a recipe for tears.
Here is the scenario.
The application is in production. need to modify one class to fix a simple bug.
Dropping a simple jar in the application without touching the whole application is a simple solution for now.
Next release can rebuild the whole application and conduct full test in QA and redeploy it.
If the use of the class is very localized (and described via an interface), then you can encapsulate its usage via a classloader of your own. If you want to redeploy the class your code can throw away the classloader, and then create a new one that loads the class from the new jar file. It's not trivial, but not particularly hard either if you understand classloaders.
Or you can make it much easier on yourself and use OSGi; this is one of its primary use cases.
If you send is by car it's a shipment, but if by ship it's cargo. This tiny ad told me: