Deploying the EJB application

As it is, you should be able to package your EJB project by issuing the following Maven goal, by starting a command-line prompt from your project root:

mvn install

The preceding command will compile and package the application that needs to be copied into the deployments folder of your application server. That's fine; however, we can expect lots more from Maven by installing just a couple of plugins. In our case, we will configure our project to use Maven's JBoss plugin by adding the following section:

<build>
   <finalName>${project.artifactId}</finalName>
   <plugins>
      <plugin>
         <groupId>org.jboss.as.plugins</groupId>
         <artifactId>jboss-as-maven-plugin</artifactId>
         <version>${version.jboss.maven.plugin}</version>
         <configuration>
            <filename>${project.build.finalName}.jar</filename>
         </configuration>
      </plugin>
      <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>2.3.1</version>
         <configuration>
            <source>1.6</source>
            <target>1.6</target>
         </configuration>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-ejb-plugin</artifactId>
         <version>2.3</version>
         <configuration>
            <ejbVersion>3.1</ejbVersion>
            <generateClient>true</generateClient>
         </configuration>
      </plugin>
   </plugins>
</build>

In the first part of the XML fragment, we have specified the project's finalName attribute that will dictate the name of the packaged artifact (in our example, the project's name corresponds to our project's artifact ID, so it will be named ticket-agency-ejb.jar).

The artifact ID named jboss-as-maven-plugin will actually trigger the JBoss Maven plugin that will be used to deploy our project.

You should also include the maven-compiler-plugin artifact that can be used to enforce the Java 1.6 compatibility and activate the annotation processors as well. Finally, maven-ejb-plugin should already be part of your pom.xml file since we have chosen an EJB archetype. You should set the generateClient option to true (the default is false) in order to create the EJB client classes.

Note

All information about plugin versions has been hardcoded into the plugin configuration for the sake of readability. As you can see from the source code that is part of this book, you should use properties to set up the core project's attributes.

So, once you have configured the JBoss plugin, your application can be deployed automatically by entering from your project root:

mvn jboss-as:deploy

Since deployment is a repetitive task for a developer, it could be convenient to execute this operation from within the Eclipse environment. All you need is to create a new Run Configuration setting from the upper menu by navigating to Run | Run Configurations.

Enter the project's base directory (hint—the Browse workspace utility will help you to pick up the project from your project list) and type your Maven goal into the Goals textbox:

Deploying the EJB application

Once done, click on Apply to save your configuration and then click on Run to execute the deployment of the application. The Maven plugins will activate and, once verified that all classes are up-to-date, start deploying the applications to JBoss AS using the remote API. You should expect a success message on the Maven console:

INFO: JBoss Remoting version 3.2.12.GA
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

On the other hand, on the JBoss AS 7 console, you have quite a verbose output that points out some important EJB JNDI bindings (we will return to it in a minute) and informs us that the application has been deployed correctly:

09:09:32,782 INFO  [org.jboss.as.server] (management-handler-thread - 1) JBAS018562: Deployed "ticket-agency-ejb.jar"
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.254.44