maven deployment start javaWEB project

To survive in the world, it is necessary to save the world, and the lights of hope also need to be accumulated.
Remember what you have learned, apply what you have learned, welcome to reprint, contact QQ:289325414 for more

Prerequisites need to be installed

1. JDK and related environment variable installation

2. TOMCAT installation

3. MAVEN installation

4. Eclipse installation

(Assuming that the first 4 have been installed)

One, eclipse creates MAVEN project

 

 

After creation, the project structure is as follows

pom.xml file 

<?xml version="1.0" encoding="UTF-8"?>

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.cjw</groupId>
  <artifactId>myapp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>myapp Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>myapp</finalName>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
  
    <plugin> 
      <groupId>org.apache.tomcat.maven</groupId> 
      <artifactId>tomcat7-maven-plugin</artifactId> 
      <version>2.2</version> 
      <configuration> 
        <url>http://localhost:8080/manager/text</url> 
        <port>8080</port>
        <username>tomcat</username> 
        <password>tomcat</password> 
  
      </configuration> 
    </plugin> 
        
      </plugins>
    </pluginManagement>
  </build>
</project>

 

TOMCAT modification

 

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

 

 

  <server>
      <username>tomcat</username>
      <password>tomcat</password>
    </server>
   

 

 Preparation is complete

Start deployment

1. Start the TOMCAT service first

 

2. CMD enters the WEB project folder directory

3. Input (mvn tomcat7: deploy)

3. The display is successful, and the webApp in the TOMCAT directory will automatically add the WAR package

 

Visit address: http://localhost:8080/myapp/index.jsp

4. To cancel the deployment, you need to enter the instructions first

mvn tomcat7:undeploy

 

Then stop the TOMCAT service, the corresponding WAR package will also be deleted

Related instructions

command description
tomcat7:run Run the current project
tomcat7:deploy Deploy the current project
tomcat7:redeploy Redeploy the project
tomcat7:exec-war Create an executable jar file, allowing the use of java -jar mywebapp.jar to run the web project
tomcat7:undeploy Undeploy a war
tomcat7:help Display help information in tomcat7-maven-plugin

 

Project source code:
https://github.com/chenjunwei111/mavenDeploy

Guess you like

Origin blog.csdn.net/qq_37203082/article/details/99431688