views:

2059

answers:

6

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.

+1  A: 

I don't know Eclipse, but I do use Netbeans. Netbeans does this pretty well. The latest version even has an option to automatically recompile when you save a java file.

I know this doesn't exactly answer your question. You can probably use both Netbeans and Eclipse depending on what part of the project you're working on.

EDIT: With Tomcat you can reload the web app. This is really only useful if Tomcat is looking at the new class. If your project is compiled to a build directory first and a WAR is then created from this you can go into Tomcat and install the web app and instead of pointing at a WAR point at the build directory.

In Tomcat you may have to put a site config file under tomcat/conf/Catalina/localhost. The contents of this file looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="C:/Projects/MyWebApp/build/web" path="/MyWebApp"/>

Instructions for reloading here: http://www.cs.ucl.ac.uk/teaching/java/tomcatfaq.html#changeservlet

If you do this a few times though Tomcat will run out of memory. This is because of something called PermGenSpace. Read up about it if you want to know more. The solution is to increase the JVM memory, the PermGenSize (with -XX:MaxPermSize) and finally restarting Tomcat occasionally.

EDIT2: If reloading the app causes you to be logged out you may be able to easily get the container to serialize your session data to disk by adding 'implements Serializable' to some of your classes. Then you should not need to login after reloading the app.

sjbotha
I cannot switch to Netbeans. It would be Great if this can be done in Eclipse.
Techmaddy
+7  A: 

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.

krosenvold
Thanks. I think Java Rebel Seems to be good. I have to test it. The only thing I am concerned is it is not a freeware/Open Source. Do you know any thing else that is freeware/OpenSource? In case your answer is No, How good is it to afford to Java Rebel?
Techmaddy
There are no other *real* alternatives as of the current jdk. Javarebel works well for me, but that's almost a separate question by itself to answer. It's not expensive and yes, it's worth it.
krosenvold
A: 

I guess I don't really see where the problem is. Here is what I do and the changes load almost instantaneously. I have an Ant script that compiles the .java and .jsp files for me, puts them in the appropriate directories under webapps and changes the web.xml file if necessary (or at least touches it to notify tomcat of the changes). If you need help on doing any of that with Ant, I'd be happy to help. Btw I do not use WAR files for deployment on my testing machine. That would be a lot slower I guess.

Kim
+1  A: 

I agree that it is very tedious to redeploy all the time when developing.

I would suggest you look into MyEclipse which has a very good hotdeploy mechanism which works well with Tomcat, and which is quite affordable and has a 30 day trial.

The stock JEE mechanism in Eclipse for redeploying to servers is nowhere as fast.

Thorbjørn Ravn Andersen
+1  A: 

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)

Scott Stanchfield
A: 

very easily done if you read this page: See http://blog.redfin.com/devblog/2009/09/how%5Fto%5Fset%5Fup%5Fhot%5Fcode%5Freplacement%5Fwith%5Ftomcat%5Fand%5Feclipse.html Thank you Dan Fabulich

Philip