简体   繁体   中英

How to setup SSL with Eclipse's maven-jetty-plugin?

I would like to be able to launch Jetty with SSL using the latest Eclipse maven-jetty-plugin and the keytool-maven-plugin as seen here . However, those two plugins are now quite outdated.

Could somebody please illustrate a working example of this using the latest versions of the plugins? Thanks!

These two plugin definitions should do it :-

<plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>maven-jetty-plugin</artifactId>
            <version>6.1.26</version>
            <configuration>
                <jvmArgs>-Xmx2048m -Xms1536m -XX:PermSize=128m -XX:MaxPermSize=256m</jvmArgs>
                <!-- http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin -->
                <scanIntervalSeconds>10</scanIntervalSeconds>
                <connectors>
                    <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                        <port>80</port>
                        <maxIdleTime>60000</maxIdleTime>
                    </connector>
                    <connector implementation="org.mortbay.jetty.security.SslSocketConnector">
                        <port>443</port>
                        <maxIdleTime>60000</maxIdleTime>
                        <keystore>${project.build.directory}/jetty-ssl.keystore</keystore>
                        <password>jetty6</password>
                        <keyPassword>jetty6</keyPassword>
                    </connector>
                </connectors>
                <contextPath>/</contextPath>
            </configuration>
        </plugin>

        <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>
                <keypass>jetty6</keypass>
                <storepass>jetty6</storepass>
                <alias>jetty6</alias>
                <keyalg>RSA</keyalg>
            </configuration>
        </plugin>

Carlspring, the trick is the implementation of the SSL connector: package and class name are modified after updates.

At version 6.1.x, the implementation was: org.mortbay.jetty.security.SslSocketConnector

After 8.x, is: org.eclipse.jetty.server.ssl.SslSocketConnector

Note that is also needed to include jetty-ssl dependency in your pom.xml.

<plugin>
  <groupId>org.mortbay.jetty</groupId>
  <artifactId>jetty-maven-plugin</artifactId>
  <version>7.0.0.pre5</version>
  <configuration>
    <connectors>
      <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
        <port>8080</port>
      </connector>
      <connector implementation="org.eclipse.jetty.server.ssl.SslSocketConnector">
        <port>8443</port>
        <keystore>src/test/resources/server.keystore</keystore>
        <keyPassword>123456</keyPassword>
        <password>123456</password>
      </connector>
    </connectors>
  </configuration>
  <dependencies>
    <dependency>
      <groupId>org.mortbay.jetty</groupId>
      <artifactId>jetty-ssl</artifactId>
      <version>7.0.0.pre5</version>
    </dependency>
  </dependencies>
</plugin>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM