如何使用https/ssl与Maven/Mortbay Jetty插件?

Ta *_*Sas 14 java ssl https maven-2 jetty

我想使用ssl/https,如中所述

http://docs.codehaus.org/display/JETTY/How+to+configure+SSL

使用jetty-maven-plugin,但我不知道如何配置插件.任何提示,示例,教程,演练?

另外,我想知道如何执行上述教程的步骤3b,其中需要对jetty服务器进行操作(java -classpath $JETTY_HOME/lib/jetty-util-6.1-SNAPSHOT.jar:$JETTY_HOME/lib/jetty-6.1-SNAPSHOT.jar org.mortbay.jetty.security.PKCS12Import jetty.pkcs12 keystore).

Pas*_*ent 25

您可以使用Maven创建开发证书并在启动Jetty时使用它.首先,配置keytool-maven-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>genkey</goal>
      </goals>
    </execution>
  </executions>
  <configuration>
    <keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
    <dname>cn=my.hostname.tld</dname><!-- put your CN here-->
    <keypass>jetty6</keypass>
    <storepass>jetty6</storepass>
    <alias>jetty6</alias>
    <keyalg>RSA</keyalg>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

根据需要更改CN.然后配置maven-jetty-plugin以使用开发证书:

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>maven-jetty-plugin</artifactId>
  <version>6.1.10</version>
  <configuration>
    <contextPath>/context</contextPath>
    <scanIntervalSeconds>5</scanIntervalSeconds>
    <connectors>
      <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
        <port>8080</port>
        <maxIdleTime>60000</maxIdleTime>
      </connector>
      <connector implementation="org.mortbay.jetty.security.SslSocketConnector">
        <port>8443</port>
        <maxIdleTime>60000</maxIdleTime>
        <keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
        <password>jetty6</password>
        <keyPassword>jetty6</keyPassword>
      </connector>
    </connectors>
  </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

运行mvn jetty:run并打开https:// localhost:8443/context.


Kum*_*hav 10

如果您使用Pascal的解决方案得到此错误: -

Could not find goal 'genkey' in plugin org.codehaus.mojo:keytool-maven-plugin:1.3
Run Code Online (Sandbox Code Playgroud)
  1. 使用'generateKeyPair'作为目标.(我相信genKey已经弃用了.)
  2. 添加插件版本.

插件定义应如下所示: -

       <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>keytool-maven-plugin</artifactId>
            <version>1.3</version>
            <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>${project.build.directory}/jetty-ssl.keystore</keystore>
                <dname>cn=my.hostname.tld</dname><!-- put your CN here -->
                <keypass>jetty6</keypass>
                <storepass>jetty6</storepass>
                <alias>jetty6</alias>
                <keyalg>RSA</keyalg>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)