I'm trying to learn Tomcat but the problem for me is the that the Tomcat server has to be restarted each time I make changes to the code.
Is there any way to make Tomcat pick up changes to the code without having to restart the server?
Maybe an IDE (Like Eclipse or NetBeans) can be somehow used to develop for Tomcat and test all the changes right there in the IDE?
Well if your putting your latest compiled files(classes/resources) under WEB-INF/Classes or lib folder you dont have to restart the server. You can can configure IDE's like Eclipse to configure this way where they can put latest compiled files under right target folder. Rcent Eclipse version comes up plugin where you can configure it to use existing tomcat server. You can also explore Mongrel Plugin which also serves the same purpose .
Please have a look at "DCEVM". It's a Java runtime environment alternative that works just like a normal JRE but is able to reload class changes in almost all situations. Very cool, and it's free.
http://dcevm.github.io/
Installation is very straightforward, see explanation on the site.
Related
I'm currently working on a GWT project in my company. Although DevMode works perfectly fine in eclipse, I still want to use Intellij Ultimate Edition for development.
But after all setups were done (Facet, Run/Debug configuration) I'm getting this weird processing window saying "Deleting Obsolete Files..." when I run the program and after that all my pre-deployed resource files in the war directory were gone (recursively...).
BTW, I use a script to deploy all my stuff. And the only argument I set for DevMode is:
-war /absolute/path/before/war/folder/war
Does anyone know the reason why Intellij is deleting my files?
After sending a request to Intellij support team, they gave me the following answer:
Adding the following two lines to the IDEA_HOME/bin/idea.properties file:
idea.gwt.clear.unit.cache.before.run=false
idea.gwt.clean.files.created.by.dev.mode=false
Which makes sense, because the only thing I need is to prevent Intellij from deleting my local cached files. Problem solved.
I switched to IntelliJ from Eclipse and never had a problem with GWT debugging in IntelliJ. It is most likely deployment-related.
First, I use Tomcat on the client side just like I'd use it in production. No built-in Jetty. Specify -noserver in Dev Mode Parameters. And make sure to start you server (in Debug mode since you are likely to debug it as well).
Other than that you may be doing custom build/deployment which is causing it. I do everything by the book. IntelliJ is Maven-centric, so it needs to be a textbook Web App module. Unlike Eclipse you don't need to specify where you war directory is. It is "webapp" per Maven convention. I suggest recreating the module from scratch.
i have tomcat project the directory structure is
previously i was using tomcat server, whenever i modified .java files i used to build the project and restarted the server in eclipse through plugin than the changes would have taken effect.
Now in my company they changed from tomcat to weblogic since i am new to it, i used to build war file every time and deploy manually to check the changes.
Can any one tell me how to do hot deployment in web logic. i googled it but it says i need to change project type to dynamic project, that i cant do since it already in development.
is their better way just make changes to java file build and no need to restart the server through eclipse in weblogic 12c.
Eclipse IDE luna
weblogic 12c server
project type : tomcat project structure
I think how you doing that is a little old fashioned. With eclipse luna, tomcat 5.0 - tomcat 8.0 is well supported. And take some effort to turn your project into a 'Dynamic Web Project', in that way you will benifit a lot from the experience of other people.
For hot redeploying, you can try JRebel, it reload your changed java class without reloading the whole applcaition.But it's a commercial software, and I don't know a good and free alternative yet.
Sorry if this is the wrong kind of question but currently I have an Apache server which is configured for Pyjamas. All I used to have to do was: pyjsbuild example.py and the GUI would appear in my browser.
I decided to switch to Java, so I picked Vaadin as my framework. How do I do the equivalent for Vaadin? All I want to do is compile the java and have Apache recognise it.
I'm using linux and I'm very new to building web applications, previously I only ever built the GUI side of things, I never had to touch the server.
You need Apache Tomcat to serve java pages. Install it separatly or see http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html for information on how to hook them together.
Vaadin projects work just as any web project. You have to crate a WAR file.
For example, if you are using Eclipse, right-click on the project, choose "Export..." and under "Web" choose "WAR file".
If you are using Netbeans or something else, google "create war in netbeans/intellij/..." to find out how to do this step.
This will generate a file with the extension .war, which you will have to copy in the "webbaps" folder of your Tomcat installation. Restart Tomcat and the application will be automatically deployed.
If you do not have access to the webapps folder, go to Tocatmcat's "Manager App" in the browser and
under the section "Fichier WAR à déployer"(WAR file to depploy) choose the generated file and click Deploy.
To start with, make sure that go through Getting Started chapter in Book of Vaadin. In this chapter you will find overview of the required toolchain and step-by-step installation instructions. Your Linux distribution might have more documentation about installing JDK (For example, see Ubuntu wiki for Oracle JDK installation).
It will be convenient for you to connect Tomcat to Eclipse IDE. This makes starting Tomcat and updating your application easy. For example, see this [blog] for some videos about connecting Eclipse to Tomcat.
Please note that using Eclipse is just one approach and later you might want to see if IntelliJ IDEA or command line works better for you.
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.
I use tomcat with eclipse in 'Use tomcat installation' mode. My problem is, that eclipse overwrites tomcats server.xml every time, and deletes my crossContext="true" elements.
Should I use custom location? Or the eclipse setup is wrong?
Thanks!
You can edit the equivalent configuration files inside your "Server" project/folder in the eclipse workspace. Those are the configuration files with which eclipse is overwriting the ones found under your Tomcat installation.
I have experienced a lot of pain getting Eclipse to interact nicely with Tomcat. I recently switched over to Jetty and I will never go back! It's especially easy to use if you use Maven as your build manager. If you use Jetty for development, you can still use Tomcat for deployment.
If you want to preserve Tomcat artifacts then you can choose "Use Workspace Metadata" option. This option will copy all configuration files to "{workspace}/.metadata/.plugins/org.eclipse.wst.server.core" directory but still use the installed Tomcat Binaries for starting and stopping server. This is a neat way to have multiple server configs using a single tomcat.