官术网_书友最值得收藏!

Project deployment

Apache Tomcat 7 will be used as the application server for this chapter. There are two popular Maven plugins that can be used to deploy applications to Tomcat: the Apache Maven plugin and the Mojo Maven plugin. By default, this book uses the Mojo Maven plugin.

To deploy a Maven project to Tomcat using the Mojo Maven plugin, the following configuration must be followed:

  1. Locate the user/conf/tomcat-users.xml file on the Tomcat server and add the desired user with administrator rights. Information like role, username and password of the added user must be added inside the <tomcat-user> tag. A sample configuration is shown in the following code snippet:
          <role rolename="manager"/> 
          <role rolename="admin"/> 
          <user username="admin" password="admin" 
          roles="admin,manager "/> 
    
    • Now save the file.
  2. Locate the file ~/.m2/settings.xml in Maven. If the file is non-existent, download Maven from its site and copy the settings.xml to ~/.m2. Open the file and locate the <servers> tag. Insert the following tag inside the <servers> tag.
            <server> 
              <id>TomcatServer</id> 
              <username>admin</username> 
              <password>admin</password> 
            </server> 
    
    • The <id> is any desired name for the Tomcat server that will be later called by the pom.xml plugin for Tomcat 7. The <username> and <password> are the server credentials manually added in /conf/tomcat-users.xml above. Save the file.
  3. Open pom.xml and add the following Maven plugin for Tomcat 7 server.
            <plugin> 
              <groupId>org.codehaus.mojo</groupId> 
              <artifactId>tomcat-maven-plugin</artifactId> 
              <version>1.1</version> 
              <configuration> 
                <url>http://localhost:8080/manager/text</url> 
                <server>TomcatServer</server> 
                <path>/ch01</path> 
              </configuration> 
            </plugin> 
    

The <configuration> settings contain information of where to deploy the project (<url>), what context root to use (<path>/), and the server name (<server>) used in the settings.xml file.

To deploy using the Apache Tomcat7 Maven plugin, the <configuration> tag only needs the <username> and <password> tags of the administration console, including the <url> and the <path>.

Maven deployment process

All projects are deployed in the Tomcat 7 server using the Maven plugin installed in STS. Follow the steps below to properly deploy the Spring MVC projects.

  1. Be sure to have a correctly configured Maven project with the appropriate POM configuration shown in the preceding figure.
  2. Right-click on the project and locate Run As in the menu options. Then, locate Maven build... in the sub-menu option, to configure the Maven goals for the first time. Maven goal is a task or command that is executed to build and manage Maven projects.
  3. After this, a Maven configuration panel will pop up to write the needed goals for deployment, and to launch the deployment process. If the Mojo Maven plugin is used, write on the Goals textbox the following: clean install tomcat:deploy. If the Apache Tomcat7 Maven plugin is used, the goals must be: clean install tomcat7:deploy. Aside from these goals, there are some that can be essential for management like remove, update and re-deploy.
  4. Click the Run button to launch the deployment. All the Maven execution logs will be shown on the console. The outcome of the deployment will be either a BUILD SUCCESS or a BUILD FAILURE.
主站蜘蛛池模板: 玛多县| 广宁县| 阿勒泰市| 全南县| 夹江县| 龙州县| 巴南区| 新建县| 扎赉特旗| 改则县| 罗田县| 龙井市| 颍上县| 邹平县| 阜城县| 浏阳市| 来安县| 江永县| 新竹市| 三河市| 八宿县| 石阡县| 奎屯市| 行唐县| 光山县| 文昌市| 奎屯市| 威宁| 甘南县| 抚顺县| 宝应县| 涪陵区| 中山市| 威信县| 红原县| 涪陵区| 吉安市| 喀喇沁旗| 榆林市| 贵南县| 平凉市|