Citation source
JETTY7/8 Maven Plugin configuration: Http://wiki.eclipse.org/Jetty/Feature/Jetty_Maven_Plugin
Jetty9 Latest Maven Plugin configuration: http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html or the latest release version
Jetty limitations for each version: Http://wiki.eclipse.org/Jetty/Starting/Jetty_Version_Comparison_Table
Jetty 7 must be JDK 1.5+,servlet 2.5, similar to Tomcat 6, the latest release version:
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactid>jetty-maven-plugin</ Artifactid> <version>7.6.16.v20140903</version></plugin>
Jetty 8 must be JDK 1.6+,servlet 3.0, similar to Tomcat 7, the latest release version:
<plugin> <groupId>org.mortbay.jetty</groupId> <artifactid>jetty-maven-plugin</ Artifactid> <version>8.1.16.v20140903</version></plugin>
Jetty 9 must be JDK 1.7+,servlet 3.0+, similar to Tomcat 8, the latest release version:
<plugin> <groupId>org.eclipse.jetty</groupId> <artifactid>jetty-maven-plugin</ Artifactid> <version>9.2.10.v20150310</version></plugin>
Many domestic applications may upgrade the JDK version, but often still use Servlet2.5 for development, so this article uses Jetty 8 as a case.
Step One
Add the following configuration to the Pom.xml of the project:
<project> .... <build> .... <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>jetty-maven-plugin</artifactId> <version>8.1.16.v20140903</version > <configuration> <scanintervalseconds>5</ scanintervalseconds> <webApp> <contextpath>/test</contextpath> </webApp> </configuration> </plugin> </plugins> .... </build> </project>
Step Two
Run using Eclipse's MAVEN build, goals configuration,
jetty:run-djetty.port=9080
The green part is because my application's Log4j.xml uses the ${sys:catalina.base} This tomcat environment variable, when starts Jetty the log4j will error, in order to solve this problem, I specially added this Catalina.base is configured and specified to a specific path. Another problem is that this configuration is not valid in environment and must be configured in Parameter for unknown reasons.
Once the above scenario has been configured, MAVEN will automatically download the plugin dependencies, compile and run the Web app for the first time, and happily access your app through the browser after successful completion.
Run Web project configuration under Eclipse with Maven's jetty plugin