Maven Jetty Plugin Examples

摘要: Few Maven Jetty 8.x and 9.x plugin examples, just for quick reference.

Few Maven Jetty 8.x and 9.x plugin examples, just for quick reference.

1. Maven Jetty Plugin 9.x

Note
You need to use Maven 3 and Java 1.7 for Maven Jetty 9.x plugin.

1.1 The ‘groupId’ is org.eclipse.jetty, by default, it runs on port 8080, in root context ‘/’.

pom.xml
  <plugin>
	<groupId>org.eclipse.jetty</groupId>
	<artifactId>jetty-maven-plugin</artifactId>
	<version>9.2.11.v20150529</version>
  </plugin>

To run the Maven Jetty plugin

terminal
$ mvn jetty:run

Deployed URL : http://localhost:8080/

To stop the running Jetty instance

terminal
$ ctrl + c

1.2 Change a context path.

pom.xml
  <plugin>
	<groupId>org.eclipse.jetty</groupId>
	<artifactId>jetty-maven-plugin</artifactId>
	<version>9.2.11.v20150529</version>
	<configuration>
		<scanIntervalSeconds>10</scanIntervalSeconds>
		<webApp>
		     <contextPath>/abc</contextPath>
		</webApp>	 
	</configuration>
  </plugin>

Deployed URL : http://localhost:8080/abc

1.3 Change a different port.

pom.xml
  <plugin>
	<groupId>org.eclipse.jetty</groupId>
	<artifactId>jetty-maven-plugin</artifactId>
	<version>9.2.11.v20150529</version>
	<configuration>
		<scanIntervalSeconds>10</scanIntervalSeconds>
		<webApp>
		     <contextPath>/abc</contextPath>
		</webApp>
		<httpConnector>
          	     <port>8888</port>
        	</httpConnector>
	</configuration>
  </plugin>

Deployed URL : http://localhost:8888/abc

Or you can pass a system property jetty.port manually :

mvn -Djetty.port=8888 jetty:run

1.4 jetty.xml example.

pom.xml
	<plugin>
	 	<groupId>org.eclipse.jetty</groupId>
		<artifactId>jetty-maven-plugin</artifactId>
		<version>9.2.11.v20150529</version>
		<configuration>
			<scanIntervalSeconds>10</scanIntervalSeconds>
			<webApp>
			      <contextPath>/abc</contextPath>
			 </webApp>
			 <jettyXml>jetty.xml</jettyXml>
		</configuration>
	</plugin>
jetty.xml
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
  <Call name="addConnector">
    <Arg>
      <New id="httpConnector" class="org.eclipse.jetty.server.ServerConnector">
        <Arg name="server"><Ref refid="Server" /></Arg>
        <Set name="host"><Property name="jetty.http.host" deprecated="jetty.host" /></Set>
        <Set name="port"><Property name="jetty.http.port" deprecated="jetty.port" default="1234" /></Set>
        <Set name="idleTimeout"><Property name="jetty.http.idleTimeout" deprecated="http.timeout" default="30000"/></Set>
      </New>
    </Arg>
  </Call>
</Configure>

Deployed URL : http://localhost:1234/abc

2. Maven Jetty Plugin 8.x

2.1 The ‘groupId’ is org.mortbay.jetty, by default, it runs on port 8080, in root context ‘/’.

pom.xml
  <plugin>
	<groupId>org.mortbay.jetty</groupId>
	<artifactId>jetty-maven-plugin</artifactId>
	<version>8.1.16.v20140903</version>
  </plugin>

2.2 Change a different context path, set seconds to check for changes and automatically hot redeploy.

pom.xml
  <plugin>
	<groupId>org.mortbay.jetty</groupId>
	<artifactId>jetty-maven-plugin</artifactId>
	<version>8.1.16.v20140903</version>
	<configuration>
		<scanIntervalSeconds>10</scanIntervalSeconds>
		<webApp>
			<contextPath>/abc</contextPath>
		</webApp>
	</configuration>
  </plugin>

Deployed URL : http://localhost:8080/abc

2.3 Change a different port to start.

pom.xml
  <plugin>
	<groupId>org.mortbay.jetty</groupId>
	<artifactId>jetty-maven-plugin</artifactId>
	<version>8.1.16.v20140903</version>	
	<configuration>
		<scanIntervalSeconds>10</scanIntervalSeconds>
		<webApp>
			<contextPath>/abc</contextPath>
		</webApp>
		<connectors>
			<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
			<port>8888</port>
			</connector>
		</connectors>
	</configuration>
  </plugin>

Deployed URL : http://localhost:8888/abc

Alternatively, you can pass a system property jetty.port manually.

mvn -Djetty.port=8888 jetty:run

P.S The class SelectChannelConnector is the default Jetty connector.

References

  1. Wikipedia : Jetty Web Server
  2. Jetty Maven Plugin 9.x
  3. Jetty Maven Plugin 8.x

上一篇: Eclipse How to change web project context root
下一篇: Gradle – Spring 4 MVC Hello World Example Annotation
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章或者资源来源于互联网, 有时候很难判断是否侵权, 若有侵权, 请联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布无版权争议的 文章/资源.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号