Deploying the Ajax application with Maven

In this section, we will compile, package, and deploy the Ajax application to WildFly 8.1 using the Maven build tool. The information about the project and the configuration details are specified in pom.xml in the root directory of the Ajax application.

As we are using the MySQL database, add a dependency on the MySQL JDBC Java Connector, as follows:

<dependency>
  <groupId>mysql</groupId>
  <artifactId>mysql-connector-java</artifactId>
  <version>5.1.22</version>
</dependency>

Add the dependency for the Servlet 3.1 API, as follows:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
</dependency>

Add the Maven compiler plugin and the Maven WAR plugin in the build element. In the configuration for the Maven WAR plugin, specify the output directory as the deployments directory of WildFly 8.1. The pom.xml file is listed as follows:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.jboss.ajax</groupId>
  <artifactId>jboss-ajax</artifactId>
  <version>1.0.0</version>
  <packaging>war</packaging>
  <name>WildFly Ajax</name>
  <description>A starter Java EE 7 webapp project for use on JBoss WildFly / WildFly, generated from the jboss-javaee6-webapp archetype</description>
  <url>http://wildfly.org</url>
  <licenses>
    <license>
      <name>Apache License, Version 2.0</name>
      <distribution>repo</distribution>
      <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
    </license>
  </licenses>
  <properties>
    <!-- Explicitly declaring the source encoding eliminates the following message: -->
    <!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- JBoss dependency versions -->
    <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
    <!-- Define the version of the JBoss BOMs we want to import to specify tested stacks. -->
    <version.jboss.bom>8.1.0.Final</version.jboss.bom>
    <version.arquillian.container>8.0.0.Final</version.arquillian.container>
    <!-- other plugin versions -->
    <version.compiler.plugin>3.1</version.compiler.plugin>
    <version.surefire.plugin>2.16</version.surefire.plugin>
    <version.war.plugin>2.1.1</version.war.plugin>
    <!-- maven-compiler-plugin -->
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.wildfly.bom</groupId>
        <artifactId>jboss-javaee-7.0-with-tools</artifactId>
        <version>${version.jboss.bom}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>org.wildfly.bom</groupId>
        <artifactId>jboss-javaee-7.0-with-hibernate</artifactId>
        <version>${version.jboss.bom}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <dependencies>
    <!-- First declare the APIs we depend on and need for compilation. All of them are provided by JBoss WildFly -->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
    </dependency>
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.22</version>
    </dependency>
  </dependencies>
  <build>
    <!-- Maven will append the version to the finalName (which is the name 	given to the generated war, and hence the context root) -->
    <finalName>${project.artifactId}</finalName>
    <plugins>
      <!-- Compiler plugin enforces Java 1.6 compatibility and activates annotation processors -->
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>${version.compiler.plugin}</version>
        <configuration>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>${version.war.plugin}</version>
        <configuration>
          <outputDirectory>C:wildfly-8.1.0.Finalstandalonedeployments</outputDirectory>
          <!-- Java EE 7 doesn't require web.xml, Maven needs to catch up! -->
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      <!-- The WildFly plugin deploys your war to a local WildFly container -->
      <!-- To use, run: mvn package wildfly:deploy -->
      <plugin>
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <version>${version.wildfly.maven.plugin}</version>
      </plugin>
    </plugins>
  </build>
</project>

After the dependencies have been added to pom.xml, the errors in the JSPs and the servlet get removed, as shown in the following screenshot:

Deploying the Ajax application with Maven

Right-click on pom.xml and select Run As | Maven install, as shown in the following screenshot:

Deploying the Ajax application with Maven

The jboss-ajax application gets compiled and packaged into jboss-ajax.war, which gets the output to the deployments directory. The Maven build outputs the message BUILD SUCCESS, as shown in the following screenshot:

Deploying the Ajax application with Maven

Start WildFly 8.1 if it is not already started. The jboss-ajax.war gets deployed to WildFly 8.1 and the web context root |jboss-ajax gets registered. The jboss-ajax.war gets deployed and gets listed in WildFly 8.1. Administration Console, as shown in the following screenshot:

Deploying the Ajax application with Maven
..................Content has been hidden....................

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