Maven, maven project deployment

Maven, maven project deployment

***Understanding the maven project and its deployment, the content of this article is relatively correct and complicated, but it is summarized after personal understanding, and I hope it will be helpful to our novices.

1. Maven understanding
2. Maven project deployment, built-in tomcat plug-in deployment (war package)

1. Maven understanding?

  1. Maven has interpretations on many websites, so I won't stick to it here, we just need to understand that it is used to manage projects. What we need to know is,
  2. The first point: the maven project will have its own set of architecture specifications, that is, the determined project directory.
    of
    This is almost the project structure. There are many ways to create such a project directory structure, such as creating a maven project on development tools such as idea, ordering to create a maven project, and even manually typing out the project directory. The point is the pom.xml file.
    The second point: Maven provides many commands for system development, such as mvn compile, mvn clean, mvn package, etc. With these commands, debugging and deployment are very convenient. For example, if you have a maven project, you don’t need development tools at all. You can directly enter the project directory. A cmd, mvn package can be easily packaged (the premise is to install Configure maven). The packaged files can be found in the target in the architecture. jar or war, and then you can deploy it (described later).
    The third point: Maven's dependency management is powerful, so I won't say much, which eliminates the pain of manual introduction. . .
    The above is a simple understanding of maven for beginners. What is maven? It turns out that he has a unique project structure and supports commands to simplify packaging. . .

2. Maven project deployment, built-in tomcat plugin deployment (war package)?

  • We all know that ordinary web projects need to be compiled and packaged before deployment, and then put the compiled files or war packages under tomcat's webapp, and then start tomcat.
    The same is true for maven projects. Ordinary maven projects also need to be packaged into war packages for project deployment.
    Now there is a problem with the tomcat plug-in in maven. After using the plug-in, we don't need the local tomcat, we can directly start the plug-in tomcat to run the project.
    So now the question is coming, my maven project contains built-in tomcat, can the war I export can be deployed and run without tomcat?
    • This is not the case, the exported war still needs tomcat to deploy and run.
      What is the use of my built-in tomcat plug-in?
    • 1. Single-step debugging of web applications can be realized. As long as you set a breakpoint in the web application program, you can realize single-step debugging when you visit the browser, and you can debug command, service, domain, and dao. From then on, we can No need to log too much. However, the fly in the ointment is that the single-step debugging of the code in the jsp cannot be achieved, but the java program compiled by the jsp can be debugged.
    • 2. Hot deployment can be realized. After the java program is modified, the modified result can be seen without restarting the application or deploying, that is, the browser does not need to log in to the system again, greatly improving the efficiency of debugging.
    • 3. Multithreading can be debugged at the same time
      . A simple sentence is convenient for development.
Let's briefly talk about the packaging and deployment of the maven project.

The first step is to package the project. If it is a web project, it is a war package. If it is a java application project, it is a jar package

  • Idea tool packaging, let’s talk about the war package first:

    Insert picture description here
    ompile compile, package package.
    The exported package files are all under target by default, as mentioned above.

  • No development tool packaging required

  • Insert picture description here

  • Find the project path, cmd under the path, enter mvn package, and the package is successful. The package is also under target.

The second step is project deployment.
Not much to say about this, put the war package into tomcat's webapp, start tomcat, it will automatically decompress your war.

There is also a java application packaged as a jar package (except for the springboot project, which is also a web project, and the principle is introduced in other chapters).

We need to know that we need to print out the jar package and be able to run java -jar ****. The premise is that there must be a main class in the project. Not only that, but we also need the plug-in to set the default startup class, so that you can java -jar *** will start your startup class.
Insert picture description here
For example, I have a main class in this project.
Then plug-in settings are required

    <pluginManagement>
          <plugins>        <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-shade-plugin</artifactId>
              <version>2.4.1</version>
              <executions>
                <execution>
                  <phase>package</phase>
                  <goals>
                    <goal>shade</goal>
                  </goals>
                  <configuration>
                    <transformers>
                      <transformer
                              implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <mainClass>HelloWorld</mainClass>
                      </transformer>
                    </transformers>
                  </configuration>
                </execution>
              </executions>
            </plugin>
          </plugins>
        </pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
      </plugin>

HelloWorld is my startup class.
After finishing these, remember to change one thing.
Insert picture description here
Change it to jar, and then package it in the same way as above. Finally, the jar package is in the target.
Start the jar package, and
Insert picture description here
that's it.

Guess you like

Origin blog.csdn.net/qq_31142237/article/details/89317806