Jetty9+Maven+HTTPS Server(SSL/TLS)详细配置

本文档详细介绍了如何使用Jetty9、Maven和HTTPS(SSL/TLS)配置服务器。涉及步骤包括设置Keystore、创建Maven项目、应用Jetty9样本配置文件,并在pom.xml中配置jetty-maven-plugin,最后成功启动HTTPS服务器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用最新的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
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值