1. Introduction

Web projects typically have three environments: dev, Test, and online; Test and Online are mostly deployed on Linux servers, so it is important for Java developers to understand the basics of Linux and how to deploy web projects locally to the server for development projects.

  • Environment on the server: JDK and Tomcat
  • For databases, large project databases are typically deployed on separate servers, so there is no need to configure a separate database environment

2. Maven automatically deploys Web projects to remote Tomcat

  • 1. Configure the Tomcat access permission on the server: Add the following tag to the Tomcat root directory conf/tomcat-user. XML on the server to enable the Manager function of Tomcat. As shown in the following figure, you can access the Manager from the local PC through http://server IP address :8080/manager (the user password is required). Tomcat webApp has several web projects such as Docs Examples host-Manager Manager by default.
<role rolename="tomcat"/>
<role rolename="manager"/>
<role rolename="manager-gui"/>
<role rolename="manager-script" />
<role rolename="admin-gui"/>
<user username="admin" password="admin" roles="tomcat,manager,manager-script,admin-gui" />
<user username="tomcat" password="tomcat" roles="manager-gui" />

Copy the code

  • 2. Add the following configuration to the pom. XML of the local Web project: pathA is the deployment path of the Tomcat server, username and password are the passwords of the user. XML account.
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>${tomcat.maven.version}</version> <configuration> <! -- HTTP port --> <url> http://server IP address :8080/manager/text</ URL > <path>/pathA</path> <username>tomcat</username> <password>tomcat</password> </configuration> </plugin> <plugin>Copy the code
  • -dskiptests skips tests -dapp_env =dev dev environment.
  • 4. Ensure that the remote Tomcat server is started
Deploy mvn-dskiptests-dapp_env =dev tomcat7:redeploy -- deploy mvn-dskiptests-dapp_env =dev tomcat7:redeploy -- You can also use the IDEA interface maven build.Copy the code
  • 5. The deployment is complete

View Tomcat run logs in real time: warName War package name tail-f /data/logs/warName.log
Copy the code

3. Idea Debug remote Tomcat

  • Why would you do that? Local tests that pass fail in the test environment, or the process can only be tested in the test environment. Because test is on the virtual machine, you cannot solve the problem by simply viewing the test environment log and cannot debug the code.
  • Use local IDEA to connect to Tomcat in the test environment and directly debug the system.

Step to more.

N. summary

Parts to know include:

  • 1. Maven packages projects
  • 2. The role of Tomcat
  • 3. Basic Use of Linux