How to stop scanning of war files during deployment on jboss - jboss5.x

During deployment the jboss deployer scans all jars inside wars it slows down the deployment.
how to stop that so that deployment speed improves.
regards
Shreyas

Project -> Properties -> Validation -> Configure Workspace settings
Disable all in Build column, except for App Client and classpath

got the same problem with JBoss 6. Still no idea how to fix it there, but about Jboss 5, looks like there is a special conf file where you can minimize scanning. Read this wiki page: JBoss5 custom metadata files, there is a sample of such a configuration, maybe it helps

Related

How to do hot deployment in Jboss5

I have got a maven project.
So when ever there is a changes done in java file, we take a rebuild of the application .
Put our ear file in deploy folder of jboss and restart the Jboss.
This waste our lot of time in restarting jboss again and again .
I heard about hot deployment in Jboss .
Can any one tell how to do in my case .
Hot deploy is enabled by default in JBoss AS 5.
It should start automatically a couple of seconds after you put ear in deploy folder.
Maybe someone had previously disabled hot deployment on your instance.
Then see Turning off JBoss hot deploy service? and do the opposite.
As I understand, u need a class reloading solution, not auto redeployment.
I recently work out a solution with JBoss 4.x. It probably work with JBoss5.x too. In most of time when I change my code, it reflects immediatly and no redeployment in JBoss.
Here is how:
Turn off JBoss hot deploy service, u can google how.
Create a folder named project.war under JBoss deploy folder, it just works like a war file.
User a file sychronize tools(like FreeFileSync) to sychronize your_project_web_root folder to the project.war folder.
The most important part, use spring-loaded. It's easy and no need to change anything in your project.
4.1 Download springloaded.jar
4.2 If u are using eclipse, just add the following code in the VM arguments of the JBoss Run Configuration.
-javaagent:/springloaded-{VERSION}.jar -noverify
That's it. Now u modify/add methods or fields in a class and then sychronize the class file to the project.war folder, JBoss will reload it and the changes reflect immediately. But springloaded still got some limitation, read the FAQ.

Eclipse JBoss hot code replace

I am using Eclipse 4.2 and JBoss 7.
I have Build automatically checked in Eclipse.
Even then I have to build and redeploy the EAR file to JBOSS to test any code changes I make in Eclipse debug mode.
Am I missing something here?
THanks,
What the "Build automatically" option in eclipse do is that when you modify the source code of a class, this one will be automatically compiled, which doesn't mean that all the whole project that contains the class (i.e. war, jar, ear ...) is redeployed in the server. But of course it helps in the speed of deployment, because the classes you've been modifying are already compiled when you manually build or deploy the project.
On the other hand, to avoid problems with redeployments, you'd better set up JBoss to delete the files related to the application keeps in the work directory, when the application is undeployed / redeployed. Look at this stackoverflow thread for more information.
Concerning the "Build automatically" option:
In order for the Deployment Scanner in JBoss to work, you have to have it turned on in JBoss.
Also, you need to add your project to the JBoss server in the Servers window. Look for the "Add or Remove..." option.
Once your project is added, any changes you make to your code will get detected and your module will be redeployed automatically in the background. Failing that and assuming your project doesn't have a snag, you can use mvn install & mvn jboss-as:deploy to manual update your module.
Beware, sometimes mvn doesn't pick up the latest java code. This seems to be a project configuration issue more than anything. Re-creating the project seems to correct the issue.
Also, keep an eye out for duplicate persistence.xml files.
You only need one.

How to call an ant target / maven after JBoss Tools Deploy?

Is there any possibility to run ant after, let's say a clean of a jboss tools server?
e.g. i plan to move some directories after having deployed them to a different directory to speed up things in jboss start up.
Another solution which came to my mind was to make jboss tools call a specific "start jboss" task/bat/something which would result in first calling my own 'move files' target then starting jboss
[EDIT - solved]
So the working solution for me was a comination of ant and jboss tools.
I use jboss 6.0.0 and jboss tools 3.2 i think
So double click the jboss 6.0.0 server, click on the tab deployment (it's a usability fail imho that this important tab is at the bottom of the view/window).
Now click on your dynamic web app module name in the list. Redirect the deployment location to yourwebappname.ear/yourwebappname.war
Use the jboss deploy folder
Move all lib files from the war/web-inf/lib to yourweappname.ear/lib
I could move all of them except spring-web-2.5.6.jar
Delete them in web-inf
eventually create and fill the meta-inf directory in yourwebappname.ear/META-INF (i did it at least) with application.xml and manifest.mf
thanks # sir Andersen
You do not reveal what kind of moves you exactly want to do and no, there is no direct support to call out to Ant or similar after a clean in JBoss Tools deploy.
But depending on what you actually want to do one or more of the below options might work for you:
Use custom deploy directory for the server
If you just need all deployments go to a specific directory then just set a custom deploy directory for the server - no need to move anything.
This is done by double clicking on the server and in the server editor under the deployments tab you can control the root directory.
Use custom deploy directory and name for specific deployments
If you need more finegrained control then you can also use the Deployments page described above to set the relative directory and name for deployment for each individual module.
Have a Ant task setup as eclipse external tool builder
If none of the above works then you could setup an Ant task as external tool builder under Project Properties. This ant launcher you can even limit to only run when certain resources changes inside the eclipse workspace - you might be able to use that to control when you want to do the "move some directories".

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.

Deployment of Web Application to a Running Tomcat

I would like to collect some best-practices on deployment of a web-application to a running Tomcat. Not long ago I had to describe the deployment process of our web-application and the process appeared rather confusing.
Say, we have an application in a WAR file (foo.war) correctly configured and not requiring additional configuration. In this case, the deployment process is rather easy:
Copy the foo.war file to the $CATALINA_HOME/webapps directory. If the application starts correctly, the application will automatically deploy to $CATALINA_HOME/webapps/foo directory.
To undeploy the application:
Remove the foo.war file from the $CATALINA_HOME/webapps. If the application unloads correctly, it will be unloaded and the $CATALINA_HOME/webapps/foo will be removed.
Now I want to override some context parameters in my running application. Having read the docs, all I need to do:
Create a context.xml file called foo.xml
Copy the file to the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory.
Unfortunately, that did not work: the application would not restart. Empirically, we found out that the only working solution is when the war file is deployed to a location outside the $CATALINA_HOME/webapps.
Besides, the default values of the configurable context parameters in the WAR file should be specified in the web.xml, since context.xml in the WAR file is not read when there is a context.xml outside.
Here is an easy example of the foo.xml:
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="/path-to-deployment-directory/foo.war">
<Parameter name="myparam" value="newvalue" override="false"/>
</Context>
Be sure to specify override=false for the parameter if you want the 'newvalue' to override the value specified in the WAR's web.xml. This was not obvious for us.
Thus, to deploy an aplication to a running Tomcat:
Create a context.xml file called foo.xml
Copy the file to the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory.
Copy the foo.war to the location specified in the docBase of the foo.xml; the application will deploy automatically.
To apply new context parameters:
Add the parameter values to the foo.xml and save the file; the application will re-deploy automatically.
To undeploy the application:
Remove the foo.xml from the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory
Note that removing the foo.war will also work, but will remove the foo.xml as well.
By now, I have the following questions:
Is it a best-practice at all to deploy a web-application without stopping the tomcat? I heard an opinion that deployment to a running tomcat is never needed since people run each application in a separate tomcat.
Is it a good idea to copy WAR files to $CATALINA_HOME/webapps or they should better be kept in a separate location?
How can I configure an application deployed to $CATALINA_HOME/webapps
Why there is no INFO line in the catalina.out for deployment of an application and there is one for undeployment? Is it configurable?
On question (1), Tomcat works great for deploying servlets into a running server. There may be concerns w.r.t. security or possibly D.O.S. or provisioning reasons why you would have separate server instances.
You have the flexibility to do either way, but it is often more convenient to deploy to an already running server. This is a BUILT-IN feature in the servlet architecture. :)
For (2), again it is at your discretion where you you want to put WARs. It sounds like you already have it configured a non-standard (non-default I should say) way. Check your server.xml file for the settings in your server instance(s). Check for attributes like unpackWARs and autoDeploy.
For (3) and (4), plus your (1,2) questions, it might be a good idea to consult the Tomcat docs for your version of Tomcat on its deployment model. You should be able to use the same docs to figure out how your server has been configured.
See Tomcat Web Application Deployment in the Tomcat manual, adjusting for your version of Tomcat.
One solution would be to use the manager application. If you decide that is safe to use it, then you can easily deploy, start, stop and undeploy applications:
http://localhost:8080/manager/deploy?path=[context_path]
http://localhost:8080/manager/start?path=[context_path]
http://localhost:8080/manager/stop?path=[context_path]
http://localhost:8080/manager/undeploy?path=[context_path]
There are ant tasks that can help you with these.
I am guessing, but do not know for sure, that stopping and starting an application will make it reread the context.xml.
Regarding your second question, I believe it is better for maintenance reasons to keep the war files in the webapps directory.