使用最新的jetty9,通过jetty-maven-plugin配置https 服务器。
Configuring the Jetty Maven Plugin
http://www.eclipse.org/jetty/documentation/current/jetty-maven-plugin.html
Jetty 9.1.2
Oracle Java SE 7u51
Eclipse Kepler (4.3.1) SR1 (Eclipse IDE for Java EE Developers)
jetty-maven-plugin
Windows7
Keystore
Server 密匙设定,自己百度,很多例子
创建maven 项目
这个应该也不难,重点在下面
使用Jetty9的sample配置文件
在 http://download.eclipse.org/jetty/ 上下载最新的Jetty9程序包
解压展开, 把etc目录下的jetty.xml, jetty-ssl.xml, jetty-https.xml 复制到 Eclipse 的项目文件夹中
cd /path/to/jetty9/etc
cp jetty.xml workspace/project/src/main/resources/config/
cp jetty-ssl.xml workspace/project/src/main/resources/config/
cp jetty-https.xml workspace/project/src/main/resources/config/
jetty.xml
不需要特殊的改变
jetty-ssl.xml
把生成的keystore复制的项目的文件夹中,改变如下的配置
...
<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
<Set name="KeyStorePath"><Property name="jetty.base" default="." />/<Property name="jetty.keystore" default="src/main/resources/keystore"/></Set>
<Set name="KeyStorePassword"><Property name="jetty.keystore.password" default="test"/></Set>
<Set name="KeyManagerPassword"><Property name="jetty.keymanager.password" default="testtest"/></Set>
<Set name="EndpointIdentificationAlgorithm"></Set>
<Set name="ExcludeCipherSuites">
...
如果没有生成keystory文件,也可以使用jetty9 文件包里etc目录下的文件,那样密码设定也不需要修改,仅供测试用。
jetty-https.xml
设定https的端口号,超时时间等。
... <Set name="host"><Property name="jetty.host" /></Set> <Set name="port"><Property name="https.port" default="9443" /></Set> <Set name="idleTimeout"><Property name="https.timeout" default="30000"/></Set> ...
pom.xml
pom.xml 文件中 jetty-maven-plugin 设定中,把上面的三个文件加载进来
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.2.6.v20141205</version>
<configuration>
<jettyConfig>${project.basedir}/src/main/resources/config/jetty.xml,${project.basedir}/src/main/resources/config/jetty-ssl.xml,${project.basedir}/src/main/resources/config/jetty-https.xml</jettyConfig>
<stopKey>STOP</stopKey>
<stopPort>9999</stopPort>
<stopWait>5</stopWait>
<scanIntervalSeconds>5</scanIntervalSeconds>
<scanTargets>
<scanTarget>${project.basedir}/src/main</scanTarget>
<scanTarget>${project.basedir}/src/test</scanTarget>
</scanTargets>
<webAppConfig>
<contextPath>/${project.artifactId}</contextPath>
</webAppConfig>
</configuration>
</plugin>
启动jetty服务器
Ecipse中 运行goal jetty:run ,jetty启动好访问https://localhost:9943/, 成功开启https服务器
22/04/2015 17:21:06.099:INFO:oejs.ServerConnector:main: Started ServerConnector@6c2fc81d{SSL-http/1.1}{0.0.0.0:9443}
[INFO] Started Jetty Server