Maven Guide

From Stax

Jump to: navigation, search

This tutorial will quickly guide you through the application creation, testing, and deployment cycle for your application using Maven.

Contents

Adding the Stax plugins to your global Maven setup

If you haven't done so already, you need to install Apache Maven.

To use the Stax commands with Maven, you need to setup Maven to see the Stax maven plugins by merging the following XML into your Maven settings.xml file (located in USER_HOME/.m2/settings.xml)

<settings>
  <pluginGroups>
    <pluginGroup>net.stax</pluginGroup>
  </pluginGroups>
  <profiles>
    <profile>
      <properties>
        <stax.username>STAX_USERNAME</stax.username>
        <stax.password>STAX_PASSWORD</stax.password>
      </properties>
      <id>dev</id>
      <repositories>
        <repository>
          <id>stax-releases</id>
          <url>http://mvn.stax.net/content/repositories/releases</url>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </repository>
        <repository>
          <id>stax-snapshots</id>
          <url>http://mvn.stax.net/content/repositories/snapshots</url>
          <releases>
            <enabled>false</enabled>
          </releases>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>stax-plugins-releases</id>
          <url>http://mvn.stax.net/content/repositories/releases</url>
          <snapshots>
            <enabled>false</enabled>
          </snapshots>
        </pluginRepository>
        <pluginRepository>
          <id>stax-plugins-snapshots</id>
          <url>http://mvn.stax.net/content/repositories/snapshots</url>
          <releases>
            <enabled>true</enabled>
          </releases>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>dev</activeProfile>
  </activeProfiles>
</settings>

Using Stax plugins from an existing Maven project

Rather than registering the Stax plugins globally (which requires every developer to make the global change manually), you can register the Stax plugins directly in with your project by merging the following XML into your project's pom.xml file.

 <repositories>
   <repository>
     <id>stax-releases</id>
     <url>http://mvn.stax.net/content/repositories/releases</url>
     <snapshots>
       <enabled>false</enabled>
     </snapshots>
   </repository>
   <repository>
     <id>stax-snapshots</id>
     <url>http://mvn.stax.net/content/repositories/snapshots</url>
     <releases>
       <enabled>false</enabled>
     </releases>
   </repository>
 </repositories>
 <pluginRepositories>
   <pluginRepository>
     <id>stax-plugins-releases</id>
     <url>http://mvn.stax.net/content/repositories/releases</url>
     <snapshots>
       <enabled>false</enabled>
     </snapshots>
   </pluginRepository>
   <pluginRepository>
     <id>stax-plugins-snapshots</id>
     <url>http://mvn.stax.net/content/repositories/snapshots</url>
     <releases>
       <enabled>true</enabled>
     </releases>
   </pluginRepository>
 </pluginRepositories>
 <build>
   <plugins>
     <plugin>
       <groupId>net.stax</groupId>
       <artifactId>stax-maven-plugin</artifactId>
     </plugin>
   </plugins>
 </build>

Application Lifecycle with Maven

Start by creating a simple webapplication using the Maven.

# mvn archetype:create -DarchetypeArtifactId=maven-archetype-webapp -DgroupId=example.myapp -DartifactId=myapp

Test your application using the mvn stax:run command inside of your new maven project directory. This will start a local instance of the Stax server for running your application. After starting the server, you can connect to http://localhost:8080 to see your running application.

# mvn stax:run

After coding and testing you application, its time to deploy the application to the Stax cloud. You can use the mvn stax:deploy command to deploy your application.

# mvn stax:deploy -Dstax.appid=myapp

Misc Tips

After your application is deployed, you can see the URL it was assigned in the command output, or your can login to Stax AppConsole to look up your application's URL.

Adding Datasources

To create datasources or assign the application ID, create a stax-web.xml file in the main/src/webapp/WEB-INF directory.

Adding Java Source files

Place your Java source files under src/main/java and they will be compiled each time you run the mvn stax:run command. Because Java application classes typically rely on the the Servlet API, you will probably want to add a definition for the Servlet API jars as <dependencies> in your pom.xml file. Since these jars will be provided at runtime for your application, you should specify the provided scope.

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version>
  <scope>provided</scope>
</dependency>

Using Eclipse

Use the following command to generate Eclipse projects for your application.

mvn eclipse:eclipse

After running this command, you can import the application as a project into Eclipse. Each time you change the dependencies in your pom.xml file, you will need to run the following command:

mvn eclipse:clean eclipse:eclipse
Personal tools
Navigation