1

I noticed that Java VM loads class on demand.

So in a large project, if we do a change to a single class and compile then will it affect the currently running java process in the system immediately?

Assume like I don't have the output stored in some JAR file.

2
  • It may affect and may not. The behavior here is not guaranteed. Commented May 25, 2014 at 7:40
  • Build should be segregated from host.
    – Sully
    Commented May 25, 2014 at 7:40

2 Answers 2

1

When you run a java project, Or in javaee War application.. Java as ClassLoader that loads all the classes, This is what the JVM Do.

http://en.wikipedia.org/wiki/Java_Classloader

So if you want to change class you have to restart your application or server.. There are frameworks to upload war "dynamically" like this one:

http://zeroturnaround.com/software/jrebel/

But if this is not for production uses.. Just restart your application :)

Hope that helps

0

Assume your speaking about dev environment?

And what is goal here - compile ONLY or compile and deploy to app server?

If your classes are being picked up frm same place as compilation then thats a best practice - you could adjust your build and deploy so its compiled in to your workspace but then classes are copied to a ..../deploy folder in correct structure and the app server picks them from there. this way no lock from running app. can compile and not deploy at will. If you want to hot deploy and they are classes not in a jar it might be possible - jvm shpould not put a lock on classes.

3
  • I mentioned that I am not using jar file to deploy the code to server. So hot deploy will work ah? JVM will not confuse and hang??
    – Athiruban
    Commented May 25, 2014 at 7:52
  • I will delete my answer - cause not sure. i think i noticed this a long time back - in the case when the class was not yet loaded. I have done it another way - by using a custom class loader - renaming the jar every time. so my app was in 3 parts - main app, class loader helper and re loadable part. i made my own code as it was just a few calsses i copied and modified from net (jar file class loader) and incorporated in my app. i had to make a new jar name every time and have a property to tell main app every time i wanted a reload (and a button-form driven function to call to reload )
    – tgkprog
    Commented May 25, 2014 at 8:01
  • will delete my answer as its not complete ... but am pretty sure its possible as long as u have time to make a few changes. if i were you i would first try to compile and deploy just the one class into deploy folder. so its all class files - replace just the one
    – tgkprog
    Commented May 25, 2014 at 8:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.