Eclipse MAVEN Deployment Web project to TOMCAT7 (compatible with TOMCAT8)

Source: Internet
Author: User

1. Download the TOMCAT7 and configure the Java_home,tomcat7\webapps directory in addition to the manager, the other can be deleted (delete useless, can speed up tomcat boot).

2. New system variable Catalina_home, value: C:\opensource\tomcat-7.0.34, add%catalina_home%\lib on the last side of the system variable path; %catalina_home%\lib\servlet-api.jar;%catalina_home%\lib\jsp-api.jar Notice the semicolon between them, which must be a semicolon in English.

3.tomcat7\conf\tomcat-users.xml Join

    <rolerolename= "Admin-gui" />    <rolerolename= "Manager-gui" />    <rolerolename= "Manager-script"/>    <Userusername= "Admin"Password= "Eteda"Roles= "Admin-gui,manager-gui,manager-script"/>

Of course, the user name and password can be different, but no manager-gui will not be able to access the Manage application through the browser, no manager-script can not upload the war package through manage to achieve the purpose of deployment.

3. Configuring MAVEN's Setting.xml

Modify%maven_home%\conf\setting.xml (provided that MAVEN enables the local installation version in MyEclipse preferences and sets the user setting.xml to conf under local setting.xml).

Add to the <servers> tab

<Server>        <ID>Tomcat7</ID>        <username>Admin</username>        <Password>Admin</Password> </Server>

Note that here the user name, password must be a user of the Manager-gui role, where the settings need to correspond to the role assignments of the previous Tomcat configuration.

4. An example of application in Web project Pom.xml ( Note: URL must also have/text, otherwise it will not upload the war package )

<Projectxmlns= "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>Com.test</groupId>    <Artifactid>TestWeb</Artifactid>    <Packaging>War</Packaging>    <version>1.0</version>    <name>TestWeb Maven Webapp</name>    <URL>http://maven.apache.org</URL>    <Properties>        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>        <Project.deploy>Deploy</Project.deploy>        <project.tomcat.version>8.0.0-rc5</project.tomcat.version>    </Properties>    <Build>        <Plugins>            <plugin>                <groupId>Org.apache.maven.plugins</groupId>                <Artifactid>Maven-compiler-plugin</Artifactid>                <version>3.1</version>                <Configuration>                    <Source>1.7</Source>                    <Target>1.7</Target>                </Configuration>            </plugin><!--             <plugin> <groupId>org.apache.maven.plugins</groupId> <arti Factid>maven-resources-plugin</artifactid> <version>2.6</version> <e                        Xecutions> <execution> <id>copy-resources</id> <phase>process-resources</phase> <goals> &L                            T;goal>resources</goal> </goals> <configuration> <encoding>UTF-8</encoding> <outputdirectory>${project.bu                                Ild.directory}/${project.deploy}</outputdirectory> <resources>                             <resource> <directory>src/main/resources/</directory>       <includes> <include>*.xml</include> </includes> </resource> </resources&                        Gt             </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artif Actid>maven-jar-plugin</artifactid> <version>2.3.2</version> <config Uration> <archive> <addmavendescriptor>false</addmavendescript Or> </archive> <outputdirectory>${project.build.directory}/${project.                Deploy}</outputdirectory> </configuration> <executions>    <execution> <phase>process-classes</phase> &LT;GOALS&G                            T                            <goal>jar</goal> </goals> <configuration>                            <excludes> <exclude>*.properties</exclude>                </excludes> </configuration> </execution>  </executions> </plugin> -            <plugin>                <groupId>Org.apache.tomcat.maven</groupId>                <Artifactid>Tomcat7-maven-plugin</Artifactid>                <version>2.2</version>                <Configuration>                    <URL>Http://localhost:8080/manager/text</URL>                    <username>Username</username>                    <Password>Password</Password>                    <Path>/${project.artifactid}</Path>                </Configuration>            </plugin>        </Plugins>    </Build>    <Dependencies>        <Dependency>            <groupId>Org.apache.tomcat</groupId>            <Artifactid>Tomcat-servlet-api</Artifactid>            <version>${project.tomcat.version}</version>            <Scope>Provided</Scope>        </Dependency>    </Dependencies></Project>

5.tomcat7 to start, in the command line go to the project directory input D:\MAVEN3\BIN\MVN tomcat7:deploy see results. (Note: not Tomcat:deploy)

Configure external maven in Eclipse, build a maven build:name in Eclipse's Run configurations a name (like Tomcat7_redeploy), select project directory for Base directory $ {workspace_loc:/testweb},goals fill tomcat7:deploy. or Tomcat7:redeploy

Deploy: If it has already been deployed, then the deploy will fail. Go to TOMCAT7 WebApps Delete already deployed is OK.

6. Five MAVEN commands that must be mastered

1). MVN Help:describe are you suffering because you can't remember what the goal of a plugin is, and if you're upset because you can't think of a certain goal parameter, try this command and it will tell you everything. Parameters: 1.-dplugin=pluginname 2. -dgoal (or-dmojo) =goalname: Used with-dplugin, it will list the goal information of a plug-in, if not enough detailed, also can add-ddetail. (Note: A plugin goal is also considered to be a "Mojo") below everyone runs MVN help:describe-dplugin=help-dmojo=describe feel it!

2). MVN archetype:generate How did you create your MAVEN project? Like this: MVN archetype:create-darchetypeartifactid= Maven-archetype-quickstart-dgroupid=com.ryanote-dartifact=common, if you use again, then you are out, modern people use MVN archetype:generate, It will create a project this boring thing more humane, you no longer need to remember so many archetypeartifactid, you just input archetype:generate, the rest is to do "choice".

3). MVN Tomcat:run After using MAVEN, you no longer need to run the Web project with Tomcat in Eclipse (the actual work often finds that it will occur in a different step), just run mvn tomat in the corresponding directory (e.g./ryanote) : The Run command, and then you can run Http://localhost:8080/ryanote in the browser. If you want more customization, you can configure it in the Pom.xml file: Org.codehaus.mojo 05 Tomcat-maven-plugin 07/web 08 9090 09 10 11 12 Of course you can also add parameters in the command to achieve a specific function, the following several more commonly used: 1. Skip test:-dmaven.test.skip (=true) 2. Specify port:-dmaven.tomcat.port=9090 3. Ignore test failure:-dmaven.test.failure.ignore=true Of course, if your other affiliate projects have been updated, be sure to run MVN clean install under the project root to perform the update, and then run MVN Tomcat: Run causes the changes to take effect.

4). Mvndebug Tomcat:run This command is mainly used for remote testing, it will listen to the remote test 8000 port, after opening the remote test in eclipse, it will run up, set breakpoints, debugging, everything is so simple. The parameters mentioned above apply here as well.

5). mvn dependency:sources so the name of meaning, with it, you do not have to find the source code, run, your project depends on the jar package source code will have

Here are a few common goal

Command Describe
Tomcat:deploy Deploy a Web War package
Tomcat:reload Reload the Web War package

Tomcat:start

Start Tomcat

Tomcat:stop

Stop Tomcat

Tomcat:undeploy

Stop a war package
Tomcat:run Start embedded Tomcat and run the current project

Eclipse MAVEN Deployment Web project to TOMCAT7 (compatible with TOMCAT8)

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.