[Java] Use jetty with Maven to check the operation.

less than 1 minute read

Introduction

When using eclipse to check the operation of a dynamic file, it only works on that terminal. So, check the operation using jetty. And personally, the directory structure of the maven project in eclipse is different and it is troublesome.

Procedure

edit pom.xml

Add the following plugins.

        <plugin>
          <groupId>org.mortbay.jetty</groupId>
          <artifactId>maven-jetty-plugin</artifactId>
          <version>6.1.10</version>
          <configuration>
            <scanIntervalSecounds>10</scanIntervalSecounds>
            <connectors>
              <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
              <port>8080</port>
              <maxIdleTime>60000</maxIdleTime>
              </connector>
            </connectors>
          </configuration>
        </plugin>

Run jetty.

Execute the following from the command line.

mvn jetty:run

Connect to localhost.

Access http://localhost:8080.

Finally

Sometimes jetty didn’t work. It took time to determine whether pom.xml was bad, the terminal was bad, or the plugin was bad. As a result, it is better to set up a container for the build and check it each time, and there is no dependency problem, so I think it is good.