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

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.

Related

Is it possible to apply changes to JSF files without republishing?

I'm using IBM RAD version 8.0 and deploying the EAR applications to IBM WebSphere 7.0. Each time I change a JSF file, I need to republish the application, otherwise the changes are not visible.
Publishing takes some time, so usually it takes minimum a minute before I'm able to see the efects of even the most minor change. In 'normal' application development it's about a few seconds, and it's crucial for someone who is no JSF coryphee and still learns and needs to experiment...
Is it possible to use the JSF ability to re-load the JSF page definition without application restarting, when working with IBM RAD and WebSphere? Or I'll be forced to create second environment with Eclipse & Tomcat, for JSF experiments only?
This is normally to be configured in server configuration. Doubleclick the desired server in Eclipse's Servers view and head to Publishing section.
Note that you should take Facelet cache into account as well, particularly when using MyFaces which caches relatively agressively. If you make sure that javax.faces.PROJECT_STAGE context parameter is set to Development, then both MyFaces and Mojarra will relax the Facelet caching strategy, causing it to recompile the Facelet file almost instantly instead of using the cached version for a rather long time.
An alternative to Publishing setting is to use JRebel. It is able to publish changes in Java classes such as managed beans and EJBs as well, saving a lot of hotdeployment time. It has an Eclipse plugin as well.
This thread is old, but I still had the same problem, using eclipse and WebSphere.
One place to check is this. If you use JSF files with the .xhtml ending, you have to make sure that changes in these do not trigger automatic republishing.
In the tab "Servers" double-click on your server.
Open the "Publishing settings for WebSphere Application Server"
Click on "Set Advanced Publishing Settings...".
In the "List of file extensions that do not trigger the server to publish ..." insert or append ", *.xhtml".
Close these settings and restart the server.
In web.xml I have also added a parameter with the name javax.faces.PROJECT_STAGE and the value Development , which may have an influence on the offending behavior.

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.

GlassFish (real) hot deployment of JSF pages and resources (CSS etc.) in Eclipse

We are wondering how to setup GlassFish 3.1.2 real hot deployment, that is not just the usual setting
How can I hot deploy using the glassfish adapter in Eclipse
but how to make it possible that the Eclipse GlassFish plugin will silently push changed XHTML, CSS, etc. files to the server as you save the file in Eclipse.
How is it officially setup?
Again, I tested this several times now, hot-deploying just-changed XHTML(/JSF), CSS files on save just doesn't work.
When setting to Never publish automatically nothing happens when saving a JSF file.
When setting to Automatically publish when resources change the whole webapp redeployment process is triggered (taking 30+ seconds!).
Q:
How is JSF, CSS hot deployment on save setup using Eclipse and the official GlassFish plugins pointed to a local, non-internal GlassFish 3.1.2?
Where do you have to look? Into the plugin or the local GF?
What makes the whole topic even more confusing is that some people get this to work easily, see http://www.java.net/forum/topic/glassfish/glassfish-plugins/glasfish-plugin#comment-819774
"just about any save of a non-java file will be visible 'immeditaely' when publish on save is active."
Not here!
It's odd... and important!
There is 'hack' that I use and works fine with maven, eclipse & GF4 hot deployment. Navigate inside your workspace where you have you xhtml project.
open .project file
edit
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments></arguments>
</buildCommand>
Modify to:
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<triggers>incremental,</triggers>
<arguments></arguments>
</buildCommand>
It works just fine for, but it might cause weird build issues (haven't tried for a long time so can't really say so use with case.)
============== Another workaround that I tried but run into eclipse/maven bugs==========
I managed to get this to work with eclipse. The steps were the following:
Double-click on glassfish->expand Publishing and make sure that you set Automatically publish when resources changes
Right-click on the server ->Glassfish and make sure User Jar Archives fro Deployement is unchecked
Then make sure you have Project-Build automatically deselected
From what I can tell maven is touching resources on save, so Glassfish restarts.
Hope it helps
If you have installed "Maven Integration for WTP" in your Eclipse, uninstall it (use m2e instead). Doing this, the hot-deployment of WebContent resources such as .xhtml and .css -files was reenabled to me. Unfortunately I don't know the reason for this workaround working.
Anyhow, I am also interested in your question of real hot-deployment (particularly of .java-files).

JBoss server does not get changes

Eclipse Indigo
Version: Indigo Service Release 1
Build id: 20110916-0149
JBoss 6.1.Final
I have a server which i have configured with some support, but it has broken down.
Broken down means, even tough i;
- stop the server,
- clean and build projects in workspace,
- and clean the server and publish from scratch,
- and start the server again
it responds like it has yesterday's code. I made lots of change but server seems not to be aware of changes.
If you have an advise on this issue, please provide.
Thanks
Try autodeploying your .war or .ear file manually, not using the Eclipse JBoss connector (which sometimes breaks down and acts strangely). Just copy the file to the autodeploy dir (for JBoss 6 i believe this is /server/default/deploy), check the JBoss's logs/console to see that your file is currently deployed, then delete it from there, and again check that the JBoss console confirms succesfully undeploying that application.
Now, that Eclipse JBoss connector is convenient because it lets you quickly deploy, debug, etc (even tho it has it's bugs). You can however to several things to simulate it's behavious without actually using it:
simplest one: Use Jetty: http://irc.codehaus.org/display/JETTY/Downloading+Jetty. Comes as Eclipse plugn, maven plugin, stand alone server. Jetty 8 supports servlet 3.0 so it's up to date. Deploying and debugging is fast and easy and it actually works (I use this a lot). Only downer: doesn't have EJB container.
Use tomcat 7 (stand alone install) and the Eclipse sysdeo plugin: http://www.eclipsetotale.com/tomcatPlugin.html. Allows for seamless deployment/debugging as you'd do with a Java SE application inside Eclipse. Again, the downer is no EJB container
If you really wanna use JBoss, try the following:
start in in debug mode all the time by adding this to your run.bat:
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n %JAVA_OPTS%
make your "target" project folder (the one where either Eclipse or Maven (whichever you use)) to be something like [jboss root]\server\default\deploy\myAppName
Start a "Remote Java application" debug session from Eclipse on the port 8787.
With all this the project should deploy any changes you make on the fly, and stop at whatever breakpoints you have when execution reaches them. It's not awesome, as sometimes certain changes will not be taken into account (eg: if you modify the body of a method in a Java class it will be hot-deployed. If you add a new method it will not).

Efficient dev cycle with Maven, Tomcat/Glassfish, Archetype?

So far i've been using tomcat and glassfish to develop a testing webapp, without maven. And the usual development-till-deploy cycle is simple :
develop in eclipse ide, with a WebContent folder, which is the root webapp folder that has the WEB-INF, web.xml, WEB-INF/lib, n all. The compiled classes location in eclipse is set to WEB-INF/classes.
after coding, i could just click on the reload button in glassfish admin console for that specific webapp. In tomcat, i believe it's reload also in the tomcat manager.
i could access the web application in the browser
Now if i would like to create a new webapp, that'll make use of latest stuffs of jsf, spring, jpa, hibernate, postgresql :
what recommendation of archetype should i use in the creation of the project ?
can i still use my previous steps of development? because i think it's very easy without having to repackage everything into a war file, or copying it into the tomcat's webapp folder everytime i want to test. Saving the files in eclipse, hit on the reload in the admin console / tomcat manager, and i could instantly test the updated webapp.
Or what do you usually do in the webapp development cycle ? Please share your experiences, =)
Thank you !
Development Cycle with Maven and Friends
Use Maven to drive your code-build-test-deploy-release cycle.
Start with Maven Archetype that suits closest to your web-app. This will create the whole folder structure for you and will add Jar depencies.
Use an embeded light-weight server like Jetty, this will be very fast on dev machine without sucking resources and is highly configurable. Plus, you can set it to auto-reload changes.
Most of Maven project are supposed to be test-driven. Of which Maven takes care of using it's surefire plug-in. So, every build will have a test phase.
You can define multiple profile for various environments (test, dev, prod, Win, Unix..). These profile will alter the behaviour of the project to be compatible with the environment.
Use Cargo, again a Maven plugin to deploy your builds on test or production server, which can be Glassfish, Tomcat, Jetty or any oter webserver.
Use Liquibase with or without Maven :) to manage your database changes the same way you manage your code change.
I came from almost similar project as yours in my previous company. Development with Maven makes things so smooth and the change is appreciable.
A little Google search shows that someone has worked on archetypes for JSF and JPA with Spring
Edit#1 -- added more details
Feasibility and Ease of Use
Maven is born out of neccessity to simplify the dev process for large and distributed code.
Maven is very well integrated with Eclipse -- so it's painless.
Jetty keeps monitoring source folders, so your changes gets deployed almost immediately.
You can customize the build to skip tests, to not build dependecies. When you just edit a UI component, Jetty will silently copy it to "target" folder.
If you're worried about copying and redeploying. You must read THIS to see how efficiently things are done, keeping in mind that you don't have to compile-test-deploy everytime you change a JSP or HTML.
That said, I would like to mention that Maven might be a challanging learning. This is an object oriented way of development cycle, to say. Most of us, who are used to build script, can find a bit tedious/verbose initially.
Resources
I would suggest to go through the following resources
Maven Book - Maven basics
Automated Deployment with Maven - going the whole nine yards If you can, literally follow this pattern.
Maven 2 Effective Implementation -- this book really helped us a lot.
for the q2 :
You can still run/debug app with tomcat from within the IDE (eclipse) even if you change the directory structure. (like the maven dir structure instead of eclipse's dynamic web dir structure)
Project properties - >
project facets - >
Dynamic Web Module ->
Click the appearing "further configuration available"
and set your content dir and context root.
You dont have to package everytime you want to run/debug it.
Another option is using Jetty
And I am sure there are more options others will tell as well.