如何使用sbt 0.7.7使用https运行jetty

时间:2013-09-05 12:29:47

标签: scala https jetty sbt

我使用的是jetty 2.1.6和sbt 0.7.7。

目前我的应用程序正在http上运行,但我希望使用https

运行

我尝试使用以下方法运行https: http://wiki.eclipse.org/Jetty/Howto/Configure_SSL#Configuring_Jetty_for_SSL

然后我在build.scala文件中设置下面的代码。

     override lazy val jettyInstance = new JettyRunner(customJettyConfiguration)
  def customJettyConfiguration = {
    val myLog = log
    val myJettyClasspath = jettyClasspath
    new CustomJettyConfiguration {
      def war = "target/scala_2.8.0/tos.war"
      def scanDirectories = Nil
      def scanInterval = 0
      def jettyClasspath = myJettyClasspath
      def classpath = jettyRunClasspath
      def classpathName = "test"
      def log = myLog
      override def jettyConfigurationXML =
        <Configure id="Server" class="org.mortbay.jetty.Server">
          <Call name="addConnector">
            <Arg>
              <New class="org.mortbay.jetty.security.SslSocketConnector">
                <Set name="Port">443</Set>
                <Set name="maxIdleTime">30000</Set>
                <Set name="handshakeTimeout">2000</Set>
                <Set name="keystore"><SystemProperty name="jetty.home" default=""/>/etc/xinetd.d/keystore</Set>
                <Set name="password">password</Set>
                <Set name="keyPassword">password</Set>
                <Set name="truststore"><SystemProperty name="jetty.home" default=""/>/etc/xinetd.d/keystore</Set>
                <Set name="trustPassword">password</Set>
                <Set name="handshakeTimeout">2000</Set>
              </New>
            </Arg>
          </Call>
          <Call name="addConnector">
            <Arg>
              <New class="org.mortbay.jetty.nio.SelectChannelConnector">
                <Set name="host"><SystemProperty name="jetty.host"/></Set>
                <Set name="port"><SystemProperty name="jetty.port" default="8080"/></Set>
                <Set name="maxIdleTime">30000</Set>
                <Set name="Acceptors">2</Set>
                <Set name="statsOn">false</Set>
                <Set name="confidentialPort">443</Set>
                <Set name="lowResourcesConnections">5000</Set>
                <Set name="lowResourcesMaxIdleTime">5000</Set>
              </New>
            </Arg>
          </Call>
        </Configure>
    }
  }

但我没有完成我的工作。

如果我做错了,请告诉我。

修改

I am using 6.1.26 version of jetty.

抱歉,我之前提到错了。

修改

现在我已成功将我的码头服务器升级到jetty-8.0.0.M3

现在,当我在build.scala文件中编写上面的代码时,我遇到了以下错误:

java.lang.NoSuchMethodError: org.eclipse.jetty.xml.XmlConfiguration.configure(Ljava/lang/Object;)V
at sbt.jetty.LazyJettyRun7$$anonfun$3.apply(LazyJettyRun7.scala:96)
at sbt.jetty.LazyJettyRun7$$anonfun$3.apply(LazyJettyRun7.scala:95)
at scala.Iterator$class.foreach(Iterator.scala:414)
at scala.List$$anon$2.foreach(List.scala:598)
at scala.Iterable$class.foreach(Iterable.scala:256)
at scala.xml.NodeSeq.foreach(NodeSeq.scala:34)
at sbt.jetty.LazyJettyRun7$.apply(LazyJettyRun7.scala:95)
at sbt.JettyRunner.runJetty$1(WebApp.scala:49)
at sbt.JettyRunner.apply(WebApp.scala:58)
at sbt.WebScalaProject$$anonfun$jettyRunTask$1.apply(ScalaProject.scala:383)
at sbt.WebScalaProject$$anonfun$jettyRunTask$1.apply(ScalaProject.scala:383)
at sbt.TaskManager$Task.invoke(TaskManager.scala:62)
at sbt.impl.RunTask.doRun$1(RunTask.scala:77)
at sbt.impl.RunTask.runTask(RunTask.scala:85)
at sbt.impl.RunTask.run(RunTask.scala:32)
at sbt.impl.RunTask$.apply(RunTask.scala:17)
at sbt.impl.RunTask$.apply(RunTask.scala:16)
at sbt.Project$class.run(Project.scala:98)
at sbt.Project$class.act(Project.scala:129)
at sbt.BasicScalaProject.act(DefaultProject.scala:21)
at sbt.xMain$$anonfun$8.apply(Main.scala:530)
at sbt.xMain$$anonfun$8.apply(Main.scala:530)
at sbt.xMain.withAction(Main.scala:563)
at sbt.xMain.sbt$xMain$$handleAction(Main.scala:530)
at sbt.xMain.handleCommand(Main.scala:520)
at sbt.xMain.processAction(Main.scala:459)
at sbt.xMain.process$1(Main.scala:257)
at sbt.xMain$Continue$1.apply(Main.scala:132)
at sbt.xMain.run$1(Main.scala:136)
at sbt.xMain.processArguments(Main.scala:266)
at sbt.xMain.startProject(Main.scala:107)
at sbt.xMain.run(Main.scala:84)
at sbt.xMain.run0$1(Main.scala:35)
at sbt.xMain.run(Main.scala:42)
at xsbt.boot.Launch$.run(Launch.scala:55)
at xsbt.boot.Launch$$anonfun$explicit$1.apply(Launch.scala:45)
at xsbt.boot.Launch$.launch(Launch.scala:69)
at xsbt.boot.Launch$.apply(Launch.scala:16)
at xsbt.boot.Boot$.runImpl(Boot.scala:31)
at xsbt.boot.Boot$.main(Boot.scala:20)
at xsbt.boot.Boot.main(Boot.scala)

[info] == jetty-run == [error]运行jetty-run时出错:运行Jetty时出错:java.lang.NoSuchMethodError:org.eclipse.jetty.xml.XmlConfiguration.configure(Ljava / lang / Object;)V

1 个答案:

答案 0 :(得分:1)

0.7.7是一个很老的SBT版本。我知道您可能有理由不升级,但如果可以的话,xsbt-web-plugin SBT插件可以让Jetty中的configuring SSL变得非常简单。