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

好久不见. 提交于 2019-12-07 14:22:52

问题


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!


回答1:


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>



回答2:


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>


来源:https://stackoverflow.com/questions/21832716/how-to-setup-ssl-with-eclipses-maven-jetty-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!