Alexander Smirnov’s personal Weblog

March 25, 2011

Maven deployer plugin for Glassfish 3.1 and Jboss

Filed under: Glassfish, Uncategorized — alexsmirnov @ 4:46 pm

Plugin features

Encouraged by the Jason Lee articles about Glassfish REST API, I added support for that API to the plugin that I use to deploy my projects, and published the code to GitHub. That’s forked from the original Maven Jboss Plugin far ago, and modified to meet my needs:

  • Find module, most suitable for deployment, in the multi-module projects. For the ‘pom’ packaging, plugin checks all dependent modules and deploys artifact with this precedence: EAR, WAR, EJB, SAR. That lets to build and deploy project to the target server in the single command: mvn package deploy.
  • Jboss downloads archives for deployment from network by http protocol. Therefore, when you deploy application to remote server, it’s necessary to put the public address of developer machine in JMX call. Plugin tries to resolve public IP for remote deployment, or can get it from configuration.
  • Added workaround for Jboss 5 bug that crashes in attempt to deploy file from url with http: protocol.
  • https: protocol added, to deploy on secured console.
  • And, at the last, it also supports Glassfish REST api with same features.

Configuration:

<project>
.....
<build>
  <plugins>
    <plugin>
      <groupId>org.richfaces.cdk</groupId>
      <artifactId>maven-deployer-plugin</artifactId>
      <version>1.0.0-SNAPSHOT</version>
      <configuration>
         <!-- configuration options -->
      <configuration>
    </plugin>
  </plugins>
</build>

Define target server

By default, plugin deploys artifact using http://localhost:4848/ URL for management application.

To define another server, use these configuration options:

  • <targetHost> – hostname or IP address of target server.
  • <targetPort> – http port where management application listening, if it different from default 4848.
  • <secure> – if you use https protocol ( enabled by asadmin enable-secure-console command ).

Authentication

By default, plugin connected to the target server as user ‘admin’ with empty password what’s Glassfish default. There are several options to define user name and password:

  1. Using <server> element in Maven settings.xml. You can create that element with the same ID as target host name, or tell plugin which id to use by <serverId> option.
  2. Define them in configuration by <username> and <password> element – not recommended for remote deployment because they visible for anyone who have acces tou your project code.
  3. use command line options -Dusername=… and -Dpassword=…

Define deployment file

For the projects with packaging ‘jar’ ‘war’ ‘ear’ ‘sar’ plugin deploys the main project artifact with the same application name as artifactId. For packaging ‘pom’, it tries to find most suitable artifact in project modules:

  1. If some module has ‘ear’ packaging, use it.
  2. Otherwise, try to find ‘war’ module.
  3. if no ‘ear’ or ‘war’ modules found, try to find ‘ejb’ or ‘sar’ modules.
  4. Otherwise, use the last module with packaging ‘jar’

The plugin has ‘aggregator’ flag in its configuration that enforces Maven to build dependent modules first. Therefore, whole project can be built and deployed by the single command:

mvn package deployer:deploy-glassfish

either from the command line, IDE or on the continuous integration server. I really use it to deploy my project to Glassfish running on Amazon EC2 cloud instance. Nirvana…

If default behavior not suitable, it can be overrided by configuration or command line options:

  • <deploymentFile>, -DdeploymentFile – path to archive to be deployed.
  • <name> -Dname – application name.
  • <contextRoot>, -DcontextRoot – web application context path.
Advertisements

Create a free website or blog at WordPress.com.