Maven in Eclipse deploys web projects to Tomcat 7 (compatible with Tomcat 8) and maventomcat7

Source: Internet
Author: User

Maven in Eclipse deploys web projects to Tomcat 7 (compatible with Tomcat 8) and maventomcat7

1. Download tomcat 7 and configure JAVA_HOME. In addition to the manager, the tomcat 7 \ webapps directory can be deleted (useless deletion can accelerate tomcat startup ).

2. create a new system variable CATALINA_HOME with the value: C: \ opensource \ tomcat-7.0.34. Add % CATALINA_HOME % \ lib; % CATALINA_HOME % \ lib \ servlet-api.jar at the end of the system variable Path; % CATALINA_HOME % \ lib \ jsp-api.jar note the semicolons between them, must be a semicolon in English.

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

    <role rolename="admin-gui" />    <role rolename="manager-gui" />    <role rolename="manager-script"/>    <user username="admin" password="eteda" roles="admin-gui,manager-gui,manager-script"/>

Of course, the user name and password can be different, but without the manager-gui, you cannot access the manage application through a browser. Without the manager-script, you cannot upload war packages through the manage to achieve the purpose of deployment.

3. Configure the setting. xml file of maven.

Modify % MAVEN_HOME % \ conf \ setting. xml (the premise is that maven enables the local installation version in myeclipse preferences and sets setting. xml as setting. xml under the Local conf ).

Add the <servers> label

<server>        <id>tomcat7</id>        <username>admin</username>        <password>admin</password> </server>

Note that the user name and password must be the manager-gui Role user. The setting must correspond to the role allocation in tomcat configuration.

4. An application example of pom. xml in a web project (Note: The url must also contain/text; otherwise, the war package cannot be uploaded.)

<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>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>                <artifactId>maven-resources-plugin</artifactId>                <version>2.6</version>                <executions>                    <execution>                        <id>copy-resources</id>                        <phase>process-resources</phase>                        <goals>                            <goal>resources</goal>                        </goals>                        <configuration>                            <encoding>UTF-8</encoding>                            <outputDirectory>${project.build.directory}/${project.deploy}</outputDirectory>                            <resources>                                <resource>                                    <directory>src/main/resources/</directory>                                    <includes>                                        <include>*.xml</include>                                    </includes>                                </resource>                            </resources>                        </configuration>                    </execution>                </executions>            </plugin>            <plugin>                <groupId>org.apache.maven.plugins</groupId>                <artifactId>maven-jar-plugin</artifactId>                <version>2.3.2</version>                <configuration>                    <archive>                        <addMavenDescriptor>false</addMavenDescriptor>                    </archive>                    <outputDirectory>${project.build.directory}/${project.deploy}</outputDirectory>                </configuration>                <executions>                    <execution>                        <phase>process-classes</phase>                        <goals>                            <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 should be started first. Input d: \ maven3 \ bin \ mvn tomcat7: deploy in the command line to go to the project directory to view the result. (Note: Not tomcat: deploy)

Configure an external maven in eclipse, and create a Maven Build: Name in eclipse's run configurations (for example, tomcat7_redeploy). Select the project directory $ {workspace_loc in Base directory: /testweb}, enter tomcat7: deploy in goals. or tomcat7: redeploy

Deploy: If deploy has been deployed, deploy will fail. Delete the deployed webapps in tomcat7.

6. Five maven commands that must be mastered

1 ). mvn help, it tells you everything. parameter: 1. -Dplugin = pluginName 2. -Dgoal (or-Dmojo) = goalName: used with-Dplugin. It lists the goal information of a plug-in. If not, add-Ddetail. (Note: A plug-in goal is also considered a "Mojo".) Run mvn help: describe-Dplugin = help-Dmojo = describe!

2). mvn archetype: generate how did you create your maven project? Is it like this: mvn archetype: create-DarchetypeArtifactId = maven-archetype-quickstart-DgroupId = com. ryanote-Dartifact = common, if you still use it, you will be out, modern people will use mvn archetype: generate, it will create a project this boring thing more humane, you no longer need to remember so many archetypeArtifactId. You only need to enter archetype: generate, and the rest is to make a "multiple choice" question.

3 ). mvn tomcat: After maven is used for run, you no longer need to use tomcat in eclipse to run web projects (in actual work, it is often found that it will not be updated synchronously ), you only need to run the mvn tomat: run Command in the corresponding directory (such as/ryanote), and then you can run http: // localhost: 8080/ryanote in the browser to view it. if you want more customization, you can go to the pom. add the following configuration to the xml file: 01 02 03 04 org. codehaus. mojo 05 tomcat-maven-plugin 06 07/web 08 9090 09 10 11 12 of course, you can also add parameters in the command to implement specific functions. The following are commonly used: 1. skip the test:-Dmaven. test. skip (= true) 2. specified port:-Dmaven. tomcat. port = 9090 3. failed to ignore test:-Dmaven. test. failure. ignore = true of course, if your other associated projects have been updated, you must run mvn clean install in the project root directory to execute the update, and then run mvn tomcat: run to make the change take effect.

4 ). mvnDebug tomcat: run this command is mainly used for remote testing. It listens to port 8000 for remote testing. After the remote test is enabled in eclipse, it will run and set breakpoints and debugging, everything is so simple. the parameters mentioned above also apply here.

5). mvn dependency: the old name of sources is "dependency". With it, you don't need to look for the source code everywhere. Run it. The source code of the jar package that your project depends on will be available.

The following describes several common Goal

Command Description
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

Related Article

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.