Sometimes right after you spent a whole day working on something (and blogging about it) you realize that there's actually an easier and faster way to accomplish the something.. d'oh (thank you very much brain
In my previous post here I was talking about an issue that I was having while trying to redeploy different versions of my application on the same glassfish context
To sum things up, the first time I deployed the application everything will work as expected but subsequent deployments will throw an error telling me that an application already exists for that context root (see message below) :
Caused by: org.codehaus.cargo.util.CargoException: Deployment has failed: Action failed Deploying application to target server failed; Error occurred during deployment: Application with name myapp-1.4.8 is already registered. Either specify that redeployment must be forced, or redeploy the application. Or if this is a new deployment, pick a different name. Please see server.log for more details.
As it turns out you can use the cargo maven plugin to redeploy your application to your glassfish server as long as you still use the glassfish application versioning system described in my previous post, you can find more info on the versionning system here but basically glassfish will handle multiple versions of your application for a given context but having only 1 active at a given moment
You can exploit the versioning system by either using the naming convention {app-name}:{appVersion}.war or specifying the version in the glassfish deployment descriptor /WEB-INF/glassfish-web.xml
For some mysterious reason the I couldn't get the deployment working with the naming convention approach so I will be showing how to accomplish the remote redeployments using the deployment descriptor :
1.- Create deployment description (if necessary) and add the application version
/myapp ${project.version}
2.- Configure your pom.xml
Once your deployment descriptor is configured you need to configure your pom.xml file to :
- Configure the maven war plugin to filter your deployment descriptor
- Configure your cargo plugin with the appropriate options corresponding to your environment
4.0.0 spring-mongodb:${project.version} ... org.apache.maven.plugins maven-war-plugin 2.1.1 false true ${basedir}/src/main/webapp/WEB-INF true WEB-INF **/glassfish-web.xml ... org.codehaus.cargo cargo-maven2-plugin 1.1.2 glassfish3x remote runtime my-remote-glassfish.com admin mypass org.glassfish.deployment deployment-client 3.1.1
3.- (Re)Deploy your application
Once you have your configuration files "configured" go to your command line (or configure a run goal in your favorite IDE) and run the following maven command (with your server started) :
mvn clean package cargo:redeploy
If everything works as expected you should get the following output for your maven command
[INFO] --- cargo-maven2-plugin:1.1.2:redeploy (default-cli) @ spring-mongodb --- [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 9.208s [INFO] Finished at: Thu Jul 04 20:35:06 CEST 2013 [INFO] Final Memory: 18M/221M [INFO] ------------------------------------------------------------------------ Process finished with exit code 0
Is there a way to do this without messing with the finalname? Seems like we should be able to set a cargo runtime arg or something. The finalname is being used by several other plugins we use and it failing the build because a colon is an invalid filename on Windows.
ReplyDeleteYes I had the same problem with a windows environment.
ReplyDeleteHave you tried leaving the default filename and creating adding the version to the deployment descriptor (/WEB-INF/glassfish-web.xml) as shown in the article? it should in theory work as the server should pick up this file when your app gets deployed.