MAVEN builds web Apps

Source: Internet
Author: User

I. Introduction of Jetty-maven-plugin

1. Configure Jetty-maven-plugin in Maven:

The following configuration is in the Pom.xml file:

1 <plugin>2     <groupId>Org.mortbay.jetty</groupId>3     <Artifactid>Jetty-maven-plugin</Artifactid>4     <version>7.1.0.rc1</version>5     <Configuration>6         <Scanintervalseconds>10</Scanintervalseconds>7         <Webappconfig>8             <ContextPath>/account</ContextPath>9         </Webappconfig>Ten     </Configuration> One </plugin>
View Code

Note: In the above configuration, scanintervalseconds indicates that the plug-in scans the time interval for project changes, and if not configured, the default value of the element is 0, which means no scanning, and the ability to automate the hot deployment is lost; ContextPath represents the context after the project is deployed Path, for example, where the value is/account, which means that the user can access the app through Http://hostname:port/account.

2. Before starting jetty, you need to make a change to the MAVEN configuration file settings.xml so that Maven supports a simplified command to invoke the jetty plugin, configured as follows:

Locate <pluginGroups></pluginGroups>in the user profile settings.xml and add the following configuration in it:

              <pluginGroup>org.mortbay.jetty</pluginGroup>

You can now start Jetty-maven-piugin by running the following command:

    $MVN Jetty:run

 Jetty-maven-piugin starts the jetty and listens to the local 8080 port by default and deploys the current project to the container, while scanning for code changes based on user configuration.

3. If you want to use a different port, you can add the Jetty.port parameter, for example:

   $MVN jetty:run-djetty.port=9990

4. To stop jetty, simply enter CTRL + C at the command line.

If you need further research on Jetty, visit the page: Http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin

II. Introduction to Automating deployment with cargo

1. Cargo is a set of tools that help users operate a Web container that enables them to automate deployment and supports all the underlying web containers, such as Tomcat, JBoss, jetty, and so on. Cargo provides MAVEN integration through Cargo-mavne2-plugin.

2. Take TOMCAT7 as an example, if you are automating the deployment of Web apps to a local or remote Web container.

2.1 Deployment to local Web container

Cargo supports two local deployment methods, standalone mode and existing mode, in standalone mode, cargo copies a copy of the configuration to the user-specified directory from the Web container's installation directory, and then deploys the application on that basis. This directory is emptied each time it is rebuilt, and all configurations are regenerated. In existing mode, the user needs to specify an existing Web container configuration directory, and then cargo will use these configurations directly and place the application to the appropriate location for the deployment expiration. Here is the Configuration sample: (Configured in the project's Pom.xml file):

Note: If you need to have MAVEN support Cargo's simplified command-line invocation, you'll need to find <pluginGroups></pluginGroups>in Maven's setting.xml configuration file. And in other configurations <pluginGroup>org.codehaus.cargo</pluginGroup>

2.1.1 Using standalone mode deployment to the local Web container

1 <plugin>2     <groupId>Org.codehaus.cargo</groupId>3     <Artifactid>Cargo-maven2-plugin</Artifactid>4     <version>1.4.9</version>5     <Configuration>6         <Container>7             <Containerid>tomcat7x</Containerid>8             <Home>E:\apache-tomcat-7.0.37</Home>9         </Container>Ten             <Configuration> One                 <type>Standalone</type> A                 <Home>${project.build.directory}/tomcat7x</Home> -                 <Properties> -                     <!--cargo default listening on port 8080, where other ports can be set - the                     <Cargo.servlet.port>8082</Cargo.servlet.port> -                 </Properties> -         </Configuration> -     </Configuration> + </plugin>
View CodeConfiguration explanation: Configuraton element: Container element: Containerid: Container type; home: The installation directory of the container; configuration element: Type: Deployment mode; Home: Indicates replication container configurations  Where the value ${project.build.directory}/tomcat7x represents the build output directory, which is the target/tomcat7x subdirectory. Properties element: Cargo.servlet.port: Container listener port number; To get cargo to start Tomcat and deploy the app, just run: $mvn cargo:start 2.1.2 Deploy to the local Web using existing mode Container
<plugin>    <groupId>Org.codehaus.cargo</groupId>    <Artifactid>Cargo-maven2-plugin</Artifactid>    <version>1.4.9</version>    <Configuration>        <Container>            <Containerid>tomcat7x</Containerid>            <Home>E:\apache-tomcat-7.0.37</Home>            </Container>            <Configuration>                <type>Existing</type>                <Home>E:\apache-tomcat-7.0.37</Home>            </Configuration>    </Configuration></plugin>
View Code

2.2 Deployment to a remote, running web container

<plugin>    <groupId>Org.codehaus.cargo</groupId>    <Artifactid>Cargo-maven2-plugin</Artifactid>    <version>1.4.9</version>    <Configuration>        <Container>            <Containerid>tomcat7x</Containerid>            <type>Remote</type>        </Container>        <Configuration>            <type>Runtime</type>            <Properties>                <Cargo.remote.username>Admin</Cargo.remote.username>                            <Cargo.remote.password>Admin</Cargo.remote.password>                          <Cargo.tomcat.manager.url>Http://localhost:8080/manager</Cargo.tomcat.manager.url>            </Properties>        </Configuration>    </Configuration></plugin>
View Code

Note: The configured user needs to have the appropriate administrator rights for the container, my admin user set the Tomcat permission to "Manager-script", set this permission can be successfully deployed, but it is recommended to set the "Manager-gui" permission, This permission allows the Admin user to log on to the Tomcat admin page.

For remote deployment, the value of the type child element of the container element must be remote, and if not explicitly specified, cargo uses the default value installed and looks for the corresponding container installation directory or installation package, for remote deployment mode, The installation directory or installation package is not required. The type child element value of the configuration is runtime, which means that neither a stand-alone container configuration nor local existing local configuration is used, but rather relies on a container that is already running, and the properties element is used to declare some configuration related to container hot deployment. It is important to note that this part of the configuration element is not consistent for all containers and needs to consult the corresponding cargo documentation.

To run the command:

$MVN Cargo:redeploy

You can deploy the current app, and if the container has already deployed the app, cargo will uninstall it and then redeploy it.

If you want to learn more about cargo, you can visit: Http://cargo.codehaus.org/Maven2+plugin

MAVEN builds web Apps

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.