search

Home  >  Q&A  >  body text

java - tomcat如何启动指定的maven项目?

PHP中文网PHP中文网2886 days ago577

reply all(4)I'll reply

  • 高洛峰

    高洛峰2017-04-18 10:46:06

    If you are working on the front-end, you should not change the back-end service code easily. Based on this premise, let’s discuss.

    1. Since it is a maven web project, you can use the maven pacakge command to package
      (you can consult if there is anything that needs special attention when packaging back-end children's shoes)

    2. Copy target/project.war to tomcat’s webapps

    3. Start up tomcat
      If there are changes to the backend code, you need to start it all over again


    Another way is to add the tomcat plug-in in the pom.xml of the maven project

    <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
            <port>8080</port>
            <path>/</path>
            <uriEncoding>UTF-8</uriEncoding>
            <finalName>${project.artifactId}</finalName>
            <server>tomcat</server>
            <systemProperties>
                <java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
                <!--
                     <JAVA_OPTS>
                         -server -Xms1024m -Xmx4096m -XX:PermSize=128M -XX:MaxPermSize=2048 -Dfile.encoding=UTF-8
                     </JAVA_OPTS>
                 -->
            </systemProperties>
        </configuration>
    </plugin>

    Run mvn tomcat7:run so you can access the backend service


    Consider another situation:

    If the backend is the spring-boot project, then you don’t need to do anything, just execute it directly in the project directory mvn spring-boot:run That’s it

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:46:06

    Just make it into a war package and throw it into the tomcatwebAPP directory

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:46:06

    There is a bin directory under tomcat, and there is a start or something in it. Copy the project into the webapps folder

    reply
    0
  • 黄舟

    黄舟2017-04-18 10:46:06

    First of all, if your project does not use an IDE, you need to compile it manually. It is very troublesome to compile the project without an IDE. Tomcat needs to run compiled class files, so you cannot specify an uncompiled project when using tomcat directly. of.

    reply
    0
  • Cancelreply