我有一个使用Jetty和Maven运行的Web服务。现在,我想为此WS创建一个SSL连接。 我在pom.xml文件中应用此代码:
pom.xml :
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>9090</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
<connector implementation="org.mortbay.jetty.security.SslSocketConnector">
<port>443</port>
<maxIdleTime>60000</maxIdleTime>
<keystore>jetty-ssl.keystore</keystore>
<password>jetty6</password>
<keyPassword>jetty6</keyPassword>
</connector>
</connectors>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>keytool-maven-plugin</artifactId>
<executions>
<execution>
<phase>generate-resources</phase>
<id>clean</id>
<goals>
<goal>clean</goal>
</goals>
</execution>
<execution>
<phase>generate-resources</phase>
<id>genkey</id>
<goals>
<goal>generateKeyPair</goal>
</goals>
</execution>
</executions>
<configuration>
<keystore>jetty-ssl.keystore</keystore>
<dname>cn=NCSL004</dname>
<keypass>jetty6</keypass>
<storepass>jetty6</storepass>
<alias>jetty6</alias>
<keyalg>RSA</keyalg>
</configuration>
</plugin>
当我运行maven时,我得到了:
> [INFO] >>> jetty-maven-plugin:8.1.13.v20130916:run (default-cli) @ Test >>>
> [INFO] --- keytool-maven-plugin:1.3:clean (clean) @ Test ---
> [INFO] Keystore file 'jetty-ssl.keystore' deleted successfully.
> [INFO]
> [INFO] --- keytool-maven-plugin:1.3:generateKeyPair (genkey) @ Test ---
> [INFO]
>
> ...
>
> 2013-12-13 10:47:46.160:INFO:oejs.AbstractConnector:Started
> SelectChannelConnector@0.0.0.0:8080 <br />
> [INFO] Started Jetty Server
当我尝试连接[https:// localhost:443]时,我收到错误,另外在[http:// localhost:9090]我也收到错误! 所以我的Web服务只适用于[http:// localhost:8080]。似乎Maven没有实现端口配置。
如何解决此错误?
谢谢!
答案 0 :(得分:1)
一些事情......
端口443
位于特殊保留空间(端口1到1024)内,因此不会发生与非特权用户的绑定。
您正在使用jetty-8.1.13,但它位于org.eclipse.jetty
命名空间中,而不是org.mortbay.jetty
,因此您的<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
行对于Jetty 8来说都是错误的。适用于Jetty 6及更早版本。
对于Jetty 8,它看起来像这样......
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.14.v20131031</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/test</contextPath>
</webApp>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>9090</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
<connector implementation="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
<port>9443</port>
<maxIdleTime>60000</maxIdleTime>
<keystore>src/test/resources/server.keystore</keystore>
<keyPassword>123456</keyPassword>
<password>123456</password>
</connector>
</connectors>
</configuration>
</plugin>