How to continuously deploy changes in JSF project without restarting Tomcat? - eclipse

I have a JSF project in Eclipse. Now every time I make changes to the .xhtml files, I have to stop Tomcat server, and then start Tomcat server again.
Is there any other way where I can continuously build and test my application without restarting the server every time I make changes?

There are at least two changes you need to make when you need to develop a JSF project:
Tell Eclipse to automatically publish changes by changing the Tomcat settings as follows (doubleclick Tomcat server entry in Servers view to get this screen):
It namely defaults to "Never publish automatically".
Tell JSF that the webapp is currently in development mode by adding the following to web.xml:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
This will change some internal workings to make the developers easier such as disabling the Facelet cache and reloading resources. Don't forget to remove this when building a production release because this affects performance. This setting can alternatively also be set by JNDI.
The alternative is to migrate from the barebones Tomcat server to a normal JEE server such as WildFly, Payara, Liberty, etc. For them, the above described Eclipse setting is not necessary anymore and you can even live edit bean methods (on Tomcat, you'd still need to restart the whole server for them).

facelets.REFRESH_PERIOD: –
interval compiler checks for page changes – lower values useful during development
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>2</param-value>
</context-param>
(or)
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
you can set any one of the above. change in web.xml
set to -1 if you don't want to effect changes made.(default value)
check this link.
Edit: as #BalusC told, above will work for jsf 1.x, For jsf 2.X change publishing settings and javax.faces.PROJECT_STAGE in web.xml.

Related

Conviniend Re-Deploy Application on Glassfish Server

In the moment the best way to redeploy an application to our glassfish servers is:
stop domain (so we don't get lots of exceptions because querys comming in while redeploy)
remove the application from the domain folder
start domain
deploy compelete application
Is there s.t. I miss that would make the process less time consuming.
Thanks Hasan
You should be able to use NetBeans integrated hot-deployment to deploy faster. NetBeans detects the files that have changed and copies only these to the deployment folder.
To enable explicitly (it should be enabled by default):
Go to Project -> Properties -> Build -> Run
Enable "Deploy on Save"
Make sure you have the following in your web.xml:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
You can ignore the exceptions on redeployment.
Another option would be to checkout JRebel.

Getting Eclipse to automatically reload the JSP pages in my Java web application

I was given a template of a Struts project to work on, and I noticed that when I run the web project on integrated Tomcat in Eclipse and make changes to the .jsp viewpages, they don't automatically reload after a few seconds - which does happen in other projects I made myself.
So I figured this was a configuration issue and I did some research, I had a look at my Tomcat server settings:
(x) Automatically publish when resources change (1 second interval)
But because my own projects reload and I use the same server for them, I figured it must be an application specific issue.
So I looked at context.xml to see if there was anything to change here
<Context
...
reloadable="true"
...
>
Which I can only assume tells the server to indeed reload the application on changes.
So I really can't figure it out. It seems to me like everything is in order here. What am I missing?
From Apache Tomcat documentation about the Context attributes:
reloadable
Set to true if you want Catalina to monitor classes in
/WEB-INF/classes/ and /WEB-INF/lib for changes, and automatically
reload the web application if a change is detected. This feature is
very useful during application development, but it requires
significant runtime overhead and is not recommended for use on
deployed production applications. That's why the default setting for
this attribute is false. You can use the Manager web application,
however, to trigger reloads of deployed applications on demand.
Also maybe this will be interesting for you: Using Tomcat Reload Features To Speed Up Development
I ran into the same problem, with a Java/Spring project that I imported via its Maven .pom files into Eclipse.
I found that I had to run the project with "Debug" instead of "Run" - only then, changes to my .jsp files were noticed, so that a reload of the web page would show the changes almost instantly.

Hot republishing/deploying of static xhtml files issues

I'm noticing a lot of issues operating the "hot deploying" of JSF pages in the following environment:
Eclipse Indigo(latest version)
Tomcat 5.5
JSF 1.2
Facelets View Handler
I noticed that, if I modify an already rendered xhtml page (for example the CSS style of an element) and then re-publish(through Eclipse or manually copying the xhtml file inside Tomcat) this page (maintaining the servlet container up), it doesn't show me the current changes.
I also, in vain, setup the following configuration on my web application:
<Context
docBase="mywebapp"
path="/mywebapp"
reloadable="true"
cachingAllowed="false">
My last tought is that the Restore-View Phase of a typical JSF page processing, does not check if the client-view (the xhtml page of course) has changed from the last time it has been loaded in the FacesContext.
If so, how can i force the building of a new UIViewRoot object for each submitted request??
I'm a lot frustrating in restarting the tomcat server for each change in jsf pages.
Thanks a lot for your support.
Try adding the following to your web.xml config file:
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
It tells JSF to re-render the Facelet. See how I put "1". In a Prod environment you would always put "-1" to disable this feature, since the facelets shouldn't be changing in a Prod environment.
You also need to make sure you can Hot Deploy class and JSP resources. You can find how to do that here:
http://ducquoc.wordpress.com/2010/11/06/eclipse-wtp-tomcat-hot-deploy/

Changes in .xhtml file not reflected in browser, restart and build needed

If I make changes in my .xhtml file, the changes are not getting reflected on the screen in my browser. To get it to work, I have to restart the server everytime. This seems unwieldy to me.
I have added the following context parameters in my web.xml:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
However, they did not have any effect.
My technology stack is listed below:
SWF 2.3.0
Primefaces 2.2.1
JSF 2
Spring Security 3
Spring 3.1.0M1I
EhCache
Apache Tomcat 6.0
STS 2.5.1.
If you're using an IDE, then you have to configure your IDE as well to publish changes to the server immediately. Otherwise the webapp which is running on the server won't get any notion of those changes.
As you're using STS which in turn is basically Eclipse for Java EE which is preloaded with a bunch of Spring specific plugins, I think that giving a generic Eclipse-targeted answer is more than sufficient.
In Eclipse, you just have to doubleclick the server entry in Servers view and then edit the Publishing section to set Automatically publish when resources changes and set the publishing interval as low as possible. It can even be 0 seconds.
That javax.faces.FACELETS_REFRESH_PERIOD only applies on the files in the webapp context. You just have to make sure that the IDE is publishing changes to the webapp context as soon as possible.
I have just spent a couple of hours before finding out that adding antiResourceLocking="true" as an attribute to the <Context> element in the applications context.xml causes the same problem in Tomcat 7: changes in facelet files are not picked up; redeployment is needed.
Removing antiResourceLocking="true" or changing it to antiResourceLocking="false" makes Tomcat work as expected for development project stage.
You should add those lines in your web.xml so that it will refresh whenever a change occurs in your .xhtml code.
<!-- JSF 2 (Facelets 2.x) -->
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>0</param-value>
</context-param>
<!-- Set the project stage to "Development", "UnitTest", "SystemTest", or "Production". -->
<!-- An optional parameter that makes troubleshooting errors much easier. -->
<!-- You should remove this context parameter before deploying to production! -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!--For JSF 1.2 (Facelets 1.x) parameters are -->
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>0</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>

Hot deploy on JBoss - how do I make JBoss "see" the change?

I am developing a Java EE application that I deploy over and over again on a local JBoss installation during development. I want to speed up the build by hot deploying my application straight into [JBOSS]/server/default/deploy/myApp
It seems to work - but there also seems to be a somewhat arbitrary delay between the hard deploy and when JBoss starts using the new classes. I am not very familiar with JBoss, but I assume it caches classes, and that this is what causes the problem.
Am I correct, and if so, how do I make JBoss flush it's cache?
I had the same problem in my bundle: (Eclipse IDE + JBoss server adapter) + JBoss AS 7.0.1 (community project).
My solution is very simple - you should go to JBoss administrative panel (by default localhost:9990), there in profile settings open Core - Deployment Scanners. Turn on Autodeploy-Exploded (set to true), and by your wishes you can set scanner time (by default 5000 ms) to appropriate for your (I set to 2000, for more fast incremental publish in Eclipse when I make changes to projects). That's it. Now JBoss makes HOT deploy not only for HTML (JSF, XHTML and so on) files, but also takes care of POJO classes (beans and so on) files.
Unfortunately, it's not that easy. There are more complicated things behind the scenes in JBoss (most of them ClassLoader related) that will prevent you from HOT-DEPLOYING your application.
For example, you are not going to be able to HOT-DEPLOY if some of your classes signatures change.
So far, using MyEclipse IDE (a paid distribution of Eclipse) is the only thing I found that does hot deploying quite successfully. Not 100% accuracy though. But certainly better than JBoss Tools, Netbeans or any other Eclipse based solution.
I've been looking for free tools to accomplish what you've just described by asking people in StackOverflow if you want to take a look.
You should try JRebel, which does the hot deploy stuff pretty well. A bit expensive, but worth the money. They have a trial version.
Just my two cents:
Cold deployment is the way of deploying an application when you stop it (or stop the whole server), then you install the new version, and finally restart the application (or start the whole server). It's suitable for official production deployments, but it would be horrible slow to do this during development. Forget about rapid development if you are doing this.
Auto deployment is the ability the server has to re-scan periodically for a new EAR/WAR and deploy it automagically behind the scenes for you, or for the IDE (Eclipse) to deploy automagically the whole application when you make changes to the source code. JBoss does this, but JBoss's marketing department call this misleadingly "hot deployment". An auto deployment is not as slow compared to a cold deployment, but is really slow compared to a hot deployment.
Hot deployment is the ability to deploy behind the scenes "as you type". No need to redeploy the whole application when you make changes. Hot deployment ONLY deploys the changes. You change a Java source code, and voila! it's running already. You never noticed it was deploying it. JBoss cannot do this, unless you buy for JRebel (or similar) but this is too much $$ for me (I'm cheap).
Now my "sales pitch" :D
What about using Tomcat during development? Comes with hot deployment all day long... for free. I do that all the time during development and then I deploy on WebSphere, JBoss, or Weblogic. Don't get me wrong, these three are great for production, but are really AWFUL for rapid-development on your local machine. Development productivity goes down the drain if you use these three all day long.
In my experience, I stopped using WebSphere, JBoss, and Weblogic for rapid development. I still have them installed in my local environment, though, but only for the occasional test I may need to run. I don't pay for JRebel all the while I get awesome development speed. Did I mention Tomcat is fully compatible with JBoss?
Tomcat is free and not only has auto-deployment, but also REAL hot deployment (Java code, JSP, JSF, XHTML) as you type in Eclipse (Yes, you read well). MYKong has a page (https://www.mkyong.com/eclipse/how-to-configure-hot-deploy-in-eclipse/) with details on how to set it up.
Did you like my sales pitch?
Cheers!
Hot deployment is stable only for changes on static parts of the application (jsf, xhtml, etc.).
Here is a working solution, according to JBoss AS 7.1.1.Final:
Build your project.Navigate to [JBOSS_HOME]/standalone/tmp/vfs.Open the most recently modified folder named "deployment[some_alphanumeric_values]", i.e. "deployment344b1c870c8edbd".Navigate to the specific view that you want to edit (usually, this is included into the packaged .war folder) and open it with a text editor (i.e. Notepad++).Make the changes you want and save the file.Refresh the respective page on your browser. The changes should be visible now.
When finished, don't forget to copy these changes to your actual development environment, rebuild and redeploy.
This worked for me in Eclipse Mars with WildFly 11. Double-click on WildFly server under Servers to open the configuration page. In the Overview tab -> Publishing, choose "Automatically publish when resources change" and set the interval to 1. Next, Overview tab -> Application Reload Behavior, uncheck the use default pattern and set the pattern to \.jar$|\.class$. In the Deployment tab, uncheck Deploy project as compressed archives. Hope this helps.
I have had the same problem, but think I've got it under control now.
Are you using eclipse or command line or ??
When I use the command line, I think I did "seam clean" or "seam undeploy" or maybe even "seam restart" followed by "seam explode". I probably tried all of these at one time or another never bothering to look up what each one does.
The idea is to remove the deployed war file from TWO places
1. $JBOSS_HOME/server/default/deploy
2. $PROJECT_HOME/exploded_archives
I'm pretty sure "seam undeploy" removes the 1st and "seam clean" removes the 2nd.
When I use eclipse (I use the free one), I first turn off "Project/Build Automatically"
Then when I am ready to deploy I do either Project/Build Project or Project/Build All depending on what I've changed. When I change xhtml, Build Project is sufficient. When I change java source Build All works. It's possible these do the same things and the difference is in my imagination, but some combination of this stuff will work for you.
You have to watch the output though. Occasionally the app does not get cleaned or undeployed. This would result in not seeing your change. Sometimes I shut down the server first and then rebuild/clean/deploy the project.
Hope this helps.
TDR
Found the solution on this link:
What to do:
configure exploded war artifact to have extension .war
deploy exploded artifact to WildFly or Jboss
configure IntelliJ to Update Resources on Update Action
When I modify a page (web), I update and when I refresh web browser: is all there with my mod.
I did configured Jboss for autoscanning (not sure it did helped)
I am using JBoss AS 7.1.1.Final. Adding following code snippet in my web.xml helped me to change jsp files on the fly :
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>development</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
</servlet>
Hope this helps.!!
Actually my problem was that the command line mvn utility wouldn't see the changes for some reason. I turned on the Auto-deploy in the Deployment Scanner and there was still no difference. HOWEVER... I was twiddling around with the Eclipse environment and because I had added a JBoss server for it's Servers window I discovered I had the ability to "Add or Remove..." modules in my workspace. Once the project was added whenever I made a change to code the code change was detected by the Deployment Scanner and JBoss went thru the cycle of updating code!!! Works like a charm.
Here are the steps necessary to set this up;
First if you haven't done so add your JBoss Server to your Eclipse using File->New->Other->Server then go thru the motions of adding your JBoss AS 7 server. Being sure to locate the directory that you are using.
Once added, look down near the bottom of Eclipse to the "Servers" tab. You should see your JBoss server. Highlight it and look for "Add or Remove...". From there you should see your project.
Once added, make a small change to your code and watch JBoss go to town hot deploying for you.
I've been developing a project with Eclipse and Wildfly and the exploded EAR file was getting big due to deploying of all the 3rd party libraries I needed in the application. I was pointing the deployment to my Maven repository which I guess was recopying the jars each time. So redeploying the application when ever I changed Java code in the service layer was turning into a nightmare.
Then having turned to Hotswap agent this helped a lot as far as seeing changes to EJB code without redeploying the application.
However I have recently upgraded to Wildfly 10, Java 8 and JBoss Developer Studio 10 and during that process I took the time to move all my 3rd party application jars e.g. primefaces into Wildfly modules and I removed my Maven repo from my deployment config. Now redeploying the entire application which is a pretty big one via Eclipse takes just a few seconds and it is much much faster than before. I don't even feel the need to install Hotswap and don't want to risk it anyway right now.
So if you are building under Eclipse with Wildfly then keep you application clear of 3rd party libs using Wildfly Modules and you'll be much better off.
Solution for Netbeans 8.02 and 8.1 IDE and JBOSS EAP 6.4:
From the services tab of Netbeans, add JBOSS server to your "servers" node.
If you are using MAVEN, netbeans compiles files and maven copies files to ./target directory. You need to create a symbolic link from .\target to JBOSS_HOME\standalone\deployments. Under windows, an example command would be
cd %JBOSS_HOME%\standalone\deployments
mklink /d MyWebApplication.war %PROJECTS_HOME%\MyWebApplication\target\MyWebApplication-1.0.0
The above creates a symbolic link from %JBOSS_HOME%\standalone\deployments\MyWebApplication.war to \target\MyWebApplication-1.0.0 which is where maven transfers all files after compilation, or after a jsp, html or any other file changes.
Last think to do is to create a CentralManagement.war.dodeploy file in %JBOSS_HOME%\standalone\deployments. This file will tell JBOSS to deploy the war "file" as a web application
Start the server in debug mode and It will track changes inside methods. Other changes It will ask to restart the module.
Deploy the app as exploded (project.war folder), add in your web.xml:
<web-app>
<context-param>
<param-name>org.jboss.weld.development</param-name>
<param-value>true</param-value>
</context-param>
Update the web.xml time every-time you deploy (append blank line):
set PRJ_HOME=C:\Temp2\MyProject\src\main\webapp
set PRJ_CLSS_HOME=%PRJ_HOME%\WEB-INF\classes\com\myProject
set JBOSS_HOME= C:\Java\jboss-4.2.3.GA-jdk6\server\default\deploy\MyProject.war
set JBOSS_CLSS_HOME= %JBOSS_HOME%\WEB-INF\classes\com\myProject
copy %PRJ_CLSS_HOME%\frontend\actions\profile\ProfileAction.class %JBOSS_CLSS_HOME%\frontend\actions\profile\ProfileAction.class
copy %PRJ_CLSS_HOME%\frontend\actions\profile\AjaxAction.class %JBOSS_CLSS_HOME%\frontend\actions\profile\AjaxAction.class
ECHO.>>%JBOSS_HOME%\WEB-INF\web.xml
In case you are working with the Eclipse IDE there is a free plugin Manik-Hotdeploy.
This plugin allows you to connect your eclipse workspace with your wildfly deployment folder. After a maven build your artifact (e.g. war or ear) will be automatically pushed into the deployment folder of your server. Also web content files (e.g. .xhtml .jsf ...) will be hot deployed.
The plugin runs for wildfly, glassfish and payara.
Read the section JBoss/Wildfly Support for more details.
In jboss-5.2.0-eap\server\default\deploy\hdscanner-jboss-beans.xml
<property name="scanPeriod">2000</property>
And, in your web.xml:
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>0</param-value>
</context-param>
<context-param>
<param-name>org.jboss.seam.core.init.debug</param-name>
<param-value>true</param-value>
</context-param>
Use Ant script and make target deploy.
The deploy target should:
Stop JBoss
Copy the ear or war to the deploy directory
Start JBoss
==> No caching + also no out of memory issues after subsequent deploys during testing.