Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile single/multiple java files without server restart? Is there any Eclipse plugin for the same?

I want to compile multiple java files in my Application without restarting Weblogic and Tomcat. Otherwise, this takes a lot of time. For this I got one Hotswap plugin in Eclipse, but this is not working in all the cases. It says it works for single file compile. Even if I use that it is not working in all the cases.

Is there any other way that I can do this or is there any other plugin/script/software which can help me in this?

If there are some open source ones, it will be very helpful.

Thanks in Advance.

like image 534
Techmaddy Avatar asked Feb 16 '09 06:02

Techmaddy


2 Answers

One thing is compiling the classes, but you also need the JAVA VM to reload the classes and use them, which is called hot-swapping. For the best available hot-swapping of classes you'll need something like javarebel. It allows you to hot-reload a lot more types of code-changes than the regular SUN JVM. If you run your deployment in exploded-mode you're home free, and can test any code change in a second or so. We're fairly test-driven, so I only use javarebel in that short phase when I assemble the whole application, but it works really well.

like image 159
krosenvold Avatar answered Nov 09 '22 12:11

krosenvold


The Java HotSpot VM does this automatically, but not in all cases...

First, you must be running a "debug" session, not a "run" session.

Next, some changes will force a restart. The basic idea is that if the interface to the class change (the method sigs, not an actual Java interface), the VM can't replace the class contents inline.

You shouldn't need a plugin for this, just a recent-ish VM.

This happens under several circumstances like

  • adding methods
  • removing methods
  • changing method signatures
  • changing the class hierarchy (superclasses, implemented interfaces)

It can also happen if you introduce an error into the class. (For errors like mismatched curly braces)

When you save a Java file, eclipse compiles it. If there is an error, eclipse inserts an exception throw to indicate that there is an unresolved compilation error. (It does this so when you run you don't just see the last successful compilation, making it obvious you have a compiler error)

like image 43
Scott Stanchfield Avatar answered Nov 09 '22 12:11

Scott Stanchfield