Smies technics


Incremental hot deployment of Maven2 JEE/JSF projects in JBoss from within Eclipse

Posted in Java, Maven2, Seam by Maurice on the January 7th, 2008

A long time ago I promised that I would explain how to do an incremental hot-deployment with a Maven2 JEE/JSF project from within Eclipse. Well here it finally is.

For this howto I will be using my new open source project called Enterprise Release Management Planner as an example. It is a simple JEE application build with Seam and off course JSF. You will find the source code here.

The project structure looks like this:

  • ermp (main project directory)
  • ermp-ear
  • ermp-ejb
  • ermp-war

Note: I use a flat project structure because I have some bad experience with the normal project structure together with Subclipse.

First we will have to setup some way to copy an exploded package to the JBoss deploy directory.
The pom file within the ermp-ear project has several profiles to create exploded and non exploded packages and copy them to a remote location.

For exploded packages the 'magic' happens in the remote-exploded-deploy profile. When this profile is activated then the EAR plugin will generate an exploded packages. The profile then uses the maven-antrun-plugin to copy the exploded packages to a remote location. This all happens in the maven package phase.
The remote location is configured in the /ermp-ear/profile.xml file. This file isn't in the SVN but there is an example in the /ermp-ear/profiles directory. Copy it to the /ermp-ear directory and set the remote-deploy-dir to your JBoss deploy directory. To make life a bit easier you should create an external tools program profile in Eclipse to execute maven on the /ermp project using the remote-exploded-deploy profile with the package phase. I am calling this profile mvn remote-exploded-deploy. Now you can simply (re)deploy the application to the JBoss deploy directory. You should do this once before continuing.

We haven't got any incremental hot deployment yet. To get it we will use the FileSync plugin. This plugin synchronizes files from within eclipse to a directory. Activate and configure this plugin on the ermp-war project. How to do that is quick straight forward. In the properties window of the project you can find the configurations screen for it. It should completely sync the src/main/webapp/ directory to the exploded WAR archive within in the exploded EAR archive of your deploy directory. Now your JSF files and other static files are hot-deployed. But it will not work for files like the WEB-INF/web.xml. You need to restart the application if you change something there. Touching the META-INF/application.xml file is enough to restart it. You can also just execute the remote-exploded-deploy external program from within Eclipse (if that doesn't take to long). I always setup an extra little remote program in Eclipse that does a touch on the file.
You can also get incremental hot deployment for the class files of the ermp-ejb project. Configure the FileSync plugin on the project to sync the /target/classes directory to the exploded JAR archive in the exploded EAR archive. This makes sure that the class files are hot-deployed, even when you restart the JBoss server. This only works when running JBoss with Debug mode, started from within Eclipse (JBoss tools ;) ) . Also if you change a class signature (rename, add, remove methods, etc...) then you need to restart the application (touching the application.xml).

After several incremental hot deployments and application restarts you will probably notice that the incremental hot deployment for class files will stop working correctly. It will look like that the debugger doesn't work correctly any more. At least I noticed this after several hours. A simple restart of the complete JBoss will do the trick.

Hopefully this post is helpfull for you. I apologize for my crappy write style. I also must note that my project is quiet new and that my pom files aren't optimized yet (I know that I should externalize the ANT scripts in the pom files to it's own build.xml file).

Writing for my Blog

Posted in Uncategorized by Maurice on the January 7th, 2008

Yes, you are right. I am not writing a lot on this Blog. My Bad. But I am about to post a new entry on hot-deployment with Seam, Eclipse and Maven.

Seam Maven2 support

Posted in Java, Development, Maven2 by Maurice on the December 15th, 2006

I just made a deal with Gavin King from JBoss that they will support my effort to create support for Seam and Maven2.

Click here to goto the forum post on it.

PS.
I will create a Post soon to explain my solution that I talked about in 'The Ultimate J2EE development environment : The search'.

The Ultimate J2EE development environment : The search

Posted in Java, Development by Maurice on the October 20th, 2006

For some time I have been looking for the ultimate J2EE development environment within Eclipse. Still I haven't found it but maybe I am getting close.

Let me first tell you what I am looking for in my ultimate j2ee development environment.

  1. It shouldn't be too hard to setup a project. I don't care if it takes me some time with the first project but it shouldn't take a lot of time every time I setup a project.
  2. It want a flexible project structure. I want to be able to say where I want my source files and where I want my compiled and packaged (or exploded) results. I also want to be able to work in multiple sub-projects.
  3. Of course it should be able to handle jar, ejb, war and ear files. But I also want to be able to work with sar, har or maybe other obscure packages.
  4. I want to be in control over my builds. What I mean is that I want to be able to easily build a more jboss specific package or maybe more specific for a different application server.
  5. I want debugging capability when I execute the application on the application server. Off course I also want debugging capabilities when I run unit tests.
  6. I want to be able to run unit test easily, with different configurations then my build. This could be necessary to simulate the correct environment. For example in Jboss Seam you need to simulate an embedded ejb server when you run unit tests. To accomplish this you need to set a different configuration value in the seam component.xml file.
  7. I want hotswap capabilities. I mean that when I am testing the application on the application server and I change something in my source code or in the jsp, html, jsf or any other static file then that change needs to be reflected to the application server instantly. I hate that I need to wait for a complete rebuild of my code and restart my application just because I changed one line of code or that I changed something in my HTML code.
  8. Other people need to be able to develop on the project easily. This means that they shouldn't spend hours on getting the environment setup. They also shouldn't need to use a specific kind of non-standard (commercial) tool.

I tried several development plugins for Eclipse. Let me tell you which and why they aren't the ultimate development environment. But I am not going into this very deep!

  • MyEclipse IDE
    This is a commercial plugin but not very expensive. It has a lot of nice features like a great jsp editor and css editor. You can also manage you database over it, sort of. It also has features for j2ee development. It has multiple project types that can put together to form an EAR package. You can then hotdeploy it to the all lot of different application servers. It also has hotswap capabilities that work pretty nice, but not perfect!
    The problem is that it is not very flexible for the project structure and I have almost nothing to say about the build process. It comes short for points 2, 4 6 and 8. But I am still going to use this tool because it has those great editors.
  • JBOSS IDE 1/ 2 beta2
    I have some experience with it because I use it at work for one project. However that project only has a sar, jar and ear archive. I haven't really tried out the new beta2 release but I did take a peak at it. The IDE has great features for developing JBPM, Seam, Jboss Rules, etc. It uses Eclipse wtp for its j2ee project structure. I don't know how for sure how this works in beta2 but in version 1 you could put your own packages together from several parts of your project (or other projects) and build you EAR package this way. You could then deploy this package to the application server. The problem is that it only supports code hotswap as long as your server is running. At the moment that you restart the server then you also need to redeploy the package.
    It comes short for points 7 and 8. I am still going to use this tool because it also has other cool tools
  • Eclipse WTP
    I tried it once a while ago. It looked a lot like the project structure from MyEclipse and it didn't really feel flexible. It also has not hotswap capabilities for non source code files. Eclipse WTP is a great base for other plugins like JBOSS IDE but it comes short for points 2, 3, 4, 7 and 8.
  • Exadel
    I only use Exadel for its great xhtml facelets editor. I saw that the other features are little bit like MyEclipse. I haven't tried out the J2EE project setup but I don't think that it will be much different then MyEclipse or Eclipse WTP.

So I discovered that these Eclipse plugins all are far from 'ultimate'. They all fail on point 8 because non of them offer generating an Ant build file or something like that. Point 7 is also a very difficult point, but for me it is one of the most critical points (or am I just picky ;) ).

As you could have read from my previous post I have been looking at Maven2. I must say that I am pretty impressed by it. It is a very powerful tool that also has an Eclipse plugin (take a look at my previous post) to bring its power to Eclipse. The cool thing is that you don't even need eclipse to work on the project (this takes care of point 8 :D ). It has it all, except for points 5 and 7. But I found a solution that will solve that too :D . More on that in my next post.

Maven 2.x Plug-in for Eclipse - version 0.0.10

Posted in Java, Development by Maurice on the October 18th, 2006

Lately I have been looking into Maven 2. I must say that I am really impressed. I want to use it for al my upcomming projects. I also found a Eclipse plugin for M2. You can find it at http://m2eclipse.codehaus.org/. This plugin works pretty nice but it is far from perfect. But it is still a 0.0.9 version so I shouldn't really complain.

I only have 2 big problems with the 0.0.9 release of the plugin. It doesn't play nice with modules of Maven 2. Let me show you what for eclipse project setup I have:

  • MainProject
    • EarModule
    • EjbModule

WebModuleThe main project,the EjbModule and WebModule are there own eclipse projects. The EarModule isn't a eclipse project because it doesn't have much in it, except the pom.xml file. It manage that module via the MainProject project.Now let me explain what the two problems are:

  • If I call Maven via 'External Tools - m2 build' with, for example, the install goal on the MainProject then Maven doesn't do much. The modules aren't being packaged. However if I call m2 via the commandline then it work
    just fine.
  • The plugin doesn't see if there are project references. For example: The WebModule has a dependency on the EjbModule. Within eclipse this should result in a project reference from WebModule to EjbModule. The plugin doesn't do that but it does adds the installed EjbModule jar from the local reposity and puts it in the 'Maven2 Dependencies' library. The result is that the WebModule project isn't uptodate with your changes in the EjbModule project.

Especially the last problem is a critical one. Luckily I discovered that both problems where solved in the 0.0.10 version of the plugin. I compiled the 0.0.10 version and tried it out. It works like a charm now.

You can download the file here: org.maven.ide.eclipse_0.0.10.jar

If you have installed a previous version of the plugin then you first need to uninstall it via the 'Product Configuration'. Then you simply copy the file in the 'plugins' directory of Eclipse. If the 'org.maven.ide.eclipse_0.0.9.jar' file is still there then you need to delete that. Offcourse you need to restart Eclipse to get it to work.

Warning: You need to change the path to the local repository folder to the actual 'repository' folder within the '.m' folder in the Maven2 plugin preferences! They changed the behaviour of this part in version 0.0.10.

Next Page »