Can Eclipse automatically refresh Tomcat app? - java

I use Eclipse Indigo (EE) to build applications in Java framework Vaadin,
using Tomcat 7.0 server. After changes in code I wont see result in a browser,
so I need to click option "Clean Tomcat Work Directory.." and wait until
Tomcat stop and start a server.
Otherwise, when I refresh app page, I don't see any changes.
Even when I restart server (and when eclipse automatically restart it when I save changes), without cleaning tomcat directory.
Option "Automatically publish when resources change" is enabled.
Is any faster way to do that? or can I automate that process?

Additionally to the answer of Kowser, it is possible do hot code changes when running tomcat in debug mode.
Otherwise you could investigate in JRebel

In your "Modules" tab of your Tomcat, you hace to clic on 'Edit' and uncheck the 'Auto reloading enables' option.
With that, several changes won't need a restart (as long as you start your server in debug mode).

If you setup your project to use ant for building and deploying, you can simply add Ant builder to your project Builders to run your ant build and deploy targets every time after you have saved a file. Then provided that tomcat is configured to support auto-deploy, this should achieve what you want, with two caveats:
If your project takes more than a few seconds to build, building after every save is not practical.
You may run out of memory for the tomcat instance if the same app is deployed to it repeatedly for a number of times. This can happen if tomcat is somehow unable to recover all the memory from undeployed resources.

It might be possible. But your setup is a bit different from what I use. I am just using tomcat+eclipse to do Servlet development using Velocity and Torque.
The following works for me where changes are visible in the browser as soon as I save in eclipse.
I assume that you have a project directory such as
apache-tomcat-7.0.11/webapps/$YOU_PROJECT/WEB-INF/classes/
Create a symbolic link with ln -s from your eclipse project directory and to the classes directory in WEB-INF.
Then configure eclipse to write all .class files to this directory. (Done by right clicking on the project in Eclipse and choosing Properties and then Java build path.
In your $tomcat/conf/context.xml config file first tag should be:
<Context allowLinking="true" reloadable="true">
Also add the following as a child to if it is not already there.
<WatchedResource>WEB-INF/web.xml</WatchedResource>
That is what I have done, but I am not sure it works with your EE tools.
ps: This solution assumes that you are using linux/unix. I don't know if it works with windows. The major problem is that eclipse can't write class files outside the project directory (Which is why that symlink is required).
btw: Tomcat may(Depending on class loader, used .jar files and other complicated details) leak a lot of memory when automatic reload is enabled so you may want to increase the allowed memory(Mostly permgen) to prevent out of memmory exceptions from tomcat.

I know this has been asked and answered very long ago. But use this info if it is helpful to anyone of you. I use Eclipse Kepler and configured Tomcat 7 server inside eclipse. I don't have to do any other configuration but to just uncheck Update context paths check box. That is all. Leave other setting as default.
In this way, changes to the resources files (xhtml pages, css files etc.) as well as the java source code files show up in the browser. Only for class files the web application would be redeployed (no server restart auto as well as manual required).
Location of Update context paths: Double click on the tomcat server under Server tab. Under Publishing tab you would find this Update context paths check box.
Absolutely no other change needs to be done for the auto publishing. This works both in normal and debug mode of tomcat.
Screen shot from my eclipse below:

No, there is no other way.
You will notice immediate changes only while updating a JSP/HTML/etc.... Classes will not be loaded/refreshed automatically. It will be contradictory to change a loaded/instantiated class when server is live, isn't it? At least it should not be possible.
It's better to perform Unit Test while developing something. It can help you to reduce the amount of annoying server restarts.

Related

Do I have to restart tomcat everything for every jsp or java change?

I am running tomcat v7.0 within my eclipse. I have to restart tomcat for every single jsp or java change. I am sure I have set my server wrong somehow. How can I see my changes without keep restarting tomcat?
Thanks!
When you are deploying to the tomcat from eclipse, If you are planning to work without deploying every time you to a change to the code base, you can use Jrebel.
Jrebel will sense your changes and take care of the re-deploying. Only issue is that It is a have to buy plugin and I know there are opensource or free applications like that.
If you are running the application in DEBUG mode, it will auto restart every time you make any change to ur JSP or java code.
You can try deleting the tomcat instance from eclipse and also the Servers folder that is present in the Project Explorer. Add your server to eclipse again and deploy your war file. The changes to JSP or javascript files will now reflect without a server restart.
That not necessary it's depend upon your configuration
When you configure Tomcat in eclipse then we have 3 option
never publish automatically
automatically publish when resource change
automatically publish after build event
so you can configure this as per your requirement.You get this option once you create tomcat server in eclipse ,then select the tomcat server,then either press F3 or right click and open.
i prefer point 2 to select and make sure you have uncheck build automatically in eclipse ,so that once you sure about all the changes you can build the project and tomcat get restart automaticcaly

How do you redeploy javascript in Idea when using a Tomcat configuration

I'm working on a java/javascript webapp that runs on tomcat.
We're working with IDEA and I've managed to get debugging set up for both the client and server code at the same time, which is great. I did have hot redeployment of the javascript set up when running Tomcat manually, however I find when running Tomcat through IDEA this doesnt work as it's setting stuff up somewhere in my users folder.
I was going to just set up a deployment configuration to go to that folder but I can't see any of the javascript files in there.
Is it possible to get the best of both worlds and have debugging and automatic deployment working together?
Update
Here's my config:
I'm using maven to build a specific profile rather than using 'build war exploded'. I suspect the latter wont work to build as quite a lot of custom properties need supplying by maven at compile time.
I also now have war exploded set in start up in deployment.
In Run - >Edit Configurations -> select tomcat instance.
then on update action : restart option
and in deployment tab instead of war use war exploded.
Now click on green button for run project it will ask option then select update resources and ok then refresh your page it will show change.
Keep one thing in mind that clear the cache.
Here is a screenshot :
It turns out I was having problems because I had antiResourceLocking=true in my tomcat context.xml config file.
I had switched this on as I was having problems with things hanging onto the war files and stopping recompilation.
changing to use antiJARLocking="true" instead seems to have solved both problems. Redeployment is now working in idea and I'm not experiencing problems with things holding files open

Is there any guide showing how to build effectively an application with appengine and maven in eclipse?

I'm trying to develop an application using Google App-Engine and Maven using Eclipse. I am facing a problem where by whenever you change a CSS or JSP file, a restart of the application is required. This makes working quite difficult, since a reload takes a lot of time.
For example when you develop on tomcat no need for restart is required when such a change is made, only Java or xml file require restart of the server.
Is there a solution that mimics the tomcat behavior on GAE SDK when developing on localhost?
If you've built using the standard app engine maven archetype, when you run mvn appengine:devserver from you -ear directory, the exploded war working directory is located here:
<yourapp>/<yourapp>-ear/target/<yourapp>-ear-1.0-SNAPSHOT/<yourapp>-war-1.0-SNAPSHOT.war
If you change any JSPs in this directory, they will get reloaded without needing to restart the devserver.
Thus, you can set up a simple script or command that copies all your JSPs and static files from /-war/src/main/webapp to that deploy directory whenever you want your files to be refreshed. I saw on some threads where people set up their IDE (in this case IntelliJ) to automatically do that copy whenever the IDE loses focuses, which makes it trivial to get pages reloaded.
Building application with appengine in eclipse using maven is not very effective and time consuming because on every change on jsp/css/js with a traditional approach there is a need to restart appengine or mvn appengine:devserver.
#adevine make me thought about a solution, and I found this link: http://andrei.gmxhome.de/filesync/index.html wich installs a plugin in eclipse, then I activate the project to sync files from myapp/src/main/webapp to a target folder generated by maven myapp/target/myapp-snapshot-0.0.1.
It's working!!!
Whenever a change is done in webapp the files are transfered automtically(no need to run anything else, just save the file) to the target folder and are reloaded successfully.
Hope this could help people because its frustrating working with appengine(restarts takes a lot).

Running tomcat from eclipse

I have tomcat setup from eclipse, so I don't have to copy the war over every time to the server. I followed some online tutorial (don't recollect which one) to set it up. I see the below issue when I click on publish -
I clicked on add and remove of my project, and published again. No change. Its still grayed out. I have set it up in such a way, that all the logs I'd typically see on the server can now be viewed on my local machine. I can't recollect how I did the setup, but as of now, I see the logs aren't getting populated either. Can anyone please help me with both these issues?
You can deploy a Tomcat application "in-place", by putting a custom <Context> element in your server.xml. This context can refer to a /www folder within your project, with your project output-path set to compile into /www/WEB-INF/classes.
For example:
<!-- JobRoute; run from within Eclipse project.
-->
<Context docBase="C:/WS/jobRoute/www" path="/jr" reloadable="true">
</Context>
Tomcat will then automatically run & reload from the /www folder within your project, can reload automatically when you recompile (if you want), and no deployment whatsoever is necessary.
Typically we use this technique & add a shortcut to start Tomcat (in debug mode) under "External Tools" in Eclipse.
As for your "Eclipse - Tomcat" builtin integration, I've never found them to work well (always difficult to configure, and generally either didn't work or awkward & slow) and gave up on those long ago. So no tips from me there.

How do I properly deploy and structure projects in Eclipse against Tomcat?

I am relatively new Java developer that's been thrown in the deep end, my usual skillset lies in Microsoft products and C#.
However I have managed to write a nice web service using Restlet and incorporating Toplink and doing some database CRUD stuff, etc etc.
I developed this in Eclipse against Tomcat 5.5. I followed tutorials and examples and managed to throw something together that works.
I had all my jar files in WebContent/WEB-INF/lib directory of my project - I soon realised that when I export this as a WAR file and deploy in Tomcat, it takes these jar files with it and stores them local to the application.
Fine, but then when you try to undeploy the app, it only does it partially as Tomcat "holds on" to some of the jars it was using i.e. the Oracle JDBC, and Toplink ones. This makes sense as the web service was using these jars as there was a live Oracle connnection going on.
So then I thought I should have all these jars in a common place where all deployed apps can access them, that folder I believe is:
C:\Program Files\Apache Software Foundation\Tomcat 5.5\common\lib
(in my case). This made total sense, it's logical as you don't want loads of apps on Tomcat all referencing the same jars. So I removed all the jars out of my projects lib folder and put them in the common\lib directory.
Now my app will not work properly - it can't find my source code in src, the custom bespoke code that I have programmed against these jars. It will only work if I jar up my source code and put in the directory stated above. Odd.
I am obviously very confused with class paths and build paths and all of that stuff, and must have got this sort of stuff all wrong as I am no Java expert, as I readily admit I have pretty much hacked this together - so can anyone explain to me in laymans terms how I should structure my project to get it working with jars held in a common folder in Tomcat. Or are there any good resoureces on the web to help explain to me what I should do.
Hope this all makes sense...
Here is a pic of my current project:
Sounds like you are not using WTP web project.
If you've installed 'Eclipse IDE for Java EE Developers' flavor of Eclipse, the WTP is already bundled in there. Otherwise here its update site -> http://download.eclipse.org/webtools/updates
Once you've installed WTP you should create 'Dynamic Web Project'.
In general I would recomment to put only your presentation layer here ( JSPs, CSS, HTML ) and put all pure java projects into standard 'Java' project that you later add as a dependency to 'Dynamic Web Project'.
WTP can run your web application under a number of containers, fortunately Tomcat is supported.
You will need to configure it through Window->Preferences->Server->Runtime Environments.
Once runtime envirnonment is configured, you can create your server runtime:
Right click in 'Servers' view.
Choose New->Server
Select server type: 'Tomcat v.5.5 Server'
(Optional) Change server name to whatever makes sense for you
Select server runtime environment: This is the Runtime Environemtn that you have configured previously
Hit 'Next' button
Add your 'Dynamic Web Project' project to 'Configured projects:' panel
Hit 'Finish' button
After the server is configured you can just run it, or you can put it in Debug mode. All source code referenced by dependent projects will be available for debugging.
NOTE:
From personal experience, I would not recommend using common/lib. Put all the jars that your web application relies upon into its WAR file. If you are worried about dependency tracking then start looking into Maven and m2eclipse.
Usually I put my jars in $CATALINA_BASE/shared/lib/
Please read this documentation for more clarification and specially Class Loader Definitions section.
Also restart the server after you copied the jars.
Go to Window > Show View > Other > Server > Servers, a servers tab will appear below with console tab. Click on your server and then F3, this will open server configuration.
Check Server Locations, and make sure you checked Use tomcat installation(takes control of tomcat installation) then click Modules tab below and it will show your installed modules, make sure the module is present or add it.

Categories