2013-07-25 35 views
10

Điều này nghe có vẻ cơ bản, nhưng thực sự khiến tôi mất cả ngày: Tôi muốn thay đổi để thay đổi cổng mà scalatra chạy, trong quá trình phát triển. Tôi bắt đầu với mẫu hello world g8 và đã xây dựng từ đó.Thay đổi cổng Scalatra

Đây là những gì tôi đã cố gắng cho đến nay:

Thay đổi cổng trong build.scala, ala tài liệu: http://www.scalatra.org/guides/deployment/configuration.html này không biên dịch, vì cổng là không xác định.

Thay đổi cổng trong build.scala, ala hai ví dụ này: https: gist.github.com ngủ gật 58af6cfbfe721a562a48 https://github.com/JamesEarlDouglas/xsbt-web-plugin/blob/master/src/sbt-test/web/servlet/project/Build.scala Cùng một vấn đề: cổng là undefined

Xác định lại điểm mấu chốt, ala http: www .scalatra.org hướng dẫn triển khai standalone.html Tuy chạy trên cổng 8080

Thay đổi params init trong bootstrap, ala http: www.scalatra.org hướng dẫn triển khai configuration.html Tuy chạy trên cổng 8080

Bất kỳ trợ giúp nào được đánh giá cao. Tôi không thể đăng hơn 2 liên kết vì một số lý do, vì vậy hãy thay thế khoảng trắng bằng dấu gạch chéo để theo dõi các url.

Đây là build.scala của tôi trong trường hợp nó trợ giúp.

import sbt._ 
import Keys._ 
import org.scalatra.sbt._ 
import org.scalatra.sbt.PluginKeys._ 
import com.mojolly.scalate.ScalatePlugin._ 
import ScalateKeys._ 
import com.earldouglas.xsbtwebplugin._ 
import WebPlugin._ 

object YesManBuild extends Build { 
    val Organization = "com.prezi" 
    val Name = "Yes Man" 
    val Version = "0.1.0-SNAPSHOT" 
    val ScalaVersion = "2.10.2" 
    val ScalatraVersion = "2.2.1" 

    //def Conf = config("container") 

    lazy val project = Project (
    "yes-man", 
    file("."), 
    settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(
     //port in Conf := 8081, 
     mainClass := Some("com.prezi.eureka.JettyLauncher.main"), 
     organization := Organization, 
     name := Name, 
     version := Version, 
     scalaVersion := ScalaVersion, 
     resolvers += Classpaths.typesafeReleases, 
     libraryDependencies ++= Seq(
     "org.slf4j" % "slf4j-log4j12" % "1.7.5", 
     "com.netflix.eureka" % "eureka-client" % "1.1.97", 
     "com.netflix.ribbon" % "ribbon-httpclient" % "0.1.10", 
     "com.netflix.ribbon" % "ribbon-eureka" % "0.1.11", 
     "org.scalatra" %% "scalatra" % ScalatraVersion, 
     "org.scalatra" %% "scalatra-scalate" % ScalatraVersion, 
     "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test", 
     "ch.qos.logback" % "logback-classic" % "1.0.6" % "runtime", 
     "org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container", 
     "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts (Artifact("javax.servlet", "jar", "jar")), 
     "org.eclipse.jetty.aggregate" % "jetty-all" % "9.0.4.v20130625" 
    ), 
     scalateTemplateConfig in Compile <<= (sourceDirectory in Compile){ base => 
     Seq(
      TemplateConfig(
      base/"webapp"/"WEB-INF"/"templates", 
      Seq.empty, /* default imports should be added here */ 
      Seq(
       Binding("context", "_root_.org.scalatra.scalate.ScalatraRenderContext", importMembers = true, isImplicit = true) 
      ), /* add extra bindings here */ 
      Some("templates") 
     ) 
     ) 
     } 
    ) 
) 
} 

Thanks guys,

~ Erik

+0

Theo tài liệu, cài đặt build.scala là: 'port in container.Configuration: = 8081' nhưng bạn có nó là' port in Conf: = 8081'. Bạn đã thử nó chính xác như họ chỉ định nó trong các tài liệu? – cmbaxter

+0

có, tôi đã thử rằng cũng – Kire321

Trả lời

14

Cập nhật 2016/01/23: scalatra-sbt sử dụng xsbt-web-plugin 2.0.4 và một vài thay đổi thiết lập. Bạn có thể tìm thấy tài liệu xsbt-web-plugin here (lưu ý liên quan: tích hợp cho xsbt-web-plugin, sbt-web, docker và xây dựng độc lập có thể được tìm thấy trong https://github.com/scalatra/scalatra-in-action, xem chapter09- * thư mục).

Đối với một ứng dụng Scalatra này có nghĩa là:

  • sử dụng jetty:start, jetty:stop thay vì container: bắt đầu, container: dừng
  • phép JettyPlugin
  • sử dụng các phím mới, ví dụ containerPort in Jetty := 8090, target in webappPrepare, sourceDirectory in webappPrepare
  • chỉ .scala dựa SBT xây dựng định nghĩa: sử dụng hàng nhập khẩu đúng để import plugin và thiết lập các phím

Một xây dựng định nghĩa .sbt:

organization := "org.foo" 
name := "My build" 
version := "0.1.0-SNAPSHOT" 
scalaVersion := "2.11.6" 

val ScalatraVersion = "2.4.0" 

libraryDependencies ++= Seq(
    "org.scalatra" %% "scalatra" % ScalatraVersion, 
    "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test", 
    "com.typesafe" % "config" % "1.2.1", 
    "ch.qos.logback" % "logback-classic" % "1.1.3" % "runtime", 
    "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided" 
) 

enablePlugins(JettyPlugin) 

containerPort in Jetty := 8090 

Một.scala dựa SBT xây dựng định nghĩa không chỉ còn lại ít chút ma thuật, và chúng ta cần phải nhập khẩu các plugin và các thiết lập của nó:

import sbt._ 
import Keys._ 

import org.scalatra.sbt._ 

import com.earldouglas.xwp.JettyPlugin 
import com.earldouglas.xwp.JettyPlugin.autoImport._ 
import com.earldouglas.xwp.ContainerPlugin.autoImport._ 

Các thực tế xây dựng định nghĩa với enablePlugins(JettyPlugin) và một cổng tùy chỉnh:

object MyBuild extends Build { 
    val Organization = "org.foo" 
    val Name = "My Build" 
    val Version = "0.1.0-SNAPSHOT" 
    val ScalaVersion = "2.11.6" 
    val ScalatraVersion = "2.4.0" 

    val mySettings = 
    ScalatraPlugin.scalatraSettings ++ Seq(
     organization := Organization, 
     name := Name, 
     version := Version, 
     scalaVersion := ScalaVersion, 
     libraryDependencies ++= Seq(
     "org.scalatra" %% "scalatra" % ScalatraVersion, 
     "org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test", 
     "com.typesafe" % "config" % "1.2.1", 
     "ch.qos.logback" % "logback-classic" % "1.1.3" % "runtime", 
     "javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided" 
    ), 
     containerPort in Jetty := 8090 
    ) 

    lazy val project = Project("chapter09", file(".")) 
    .enablePlugins(JettyPlugin) 
    .settings(mySettings: _*) 

} 

Đảm bảo bạn đang sử dụng hàng nhập:

import com.earldouglas.xsbtwebplugin.PluginKeys._ 
import com.earldouglas.xsbtwebplugin.WebPlugin._ 

Với những lần nhập bạn có thể sử dụng thì chìa khóa chính xác và cấu hình:

port in container.Configuration := 9000 

này đi trong khối settings:

... 
lazy val project = Project (
    "example", 
    file("."), 
    settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ scalateSettings ++ Seq(
    port in container.Configuration := 9000, 
    organization := Organization, 
... 

scalatra-SBT được xây dựng trên xsbt-web-plugin mà thiết lập được ghi nhận ở đây: https://github.com/JamesEarlDouglas/xsbt-web-plugin/wiki/Settings

+0

Điều này hoạt động hoàn hảo. Tôi sẽ xem liệu tôi có thể khiến họ thêm tài liệu này vào tài liệu chính thức vì ví dụ của họ không hoạt động nếu không có nó. – jlegler

+0

Nhập khẩu đó không còn hoạt động: 'đối tượng xsbtwebplugin không phải là thành viên của gói com.earldouglas'. Lời khuyên nào? –

+0

@AhmedFasih Tôi đã cập nhật bài đăng lên phiên bản plugin mới nhất của phiên bản scalatra-sbt và xsbt-web-plugin. –

1

Tôi đã làm điều này và làm việc:

.... 
val port = SettingKey[Int]("port") 
val Conf = config("container") 

lazy val project = Project (
    port in Conf := 8081, 
    .... 
) 
0

Tôi đã tạo tệp build.sbt trống trong e gốc của dự án của tôi và đặt:

port in container.Configuration := 8090

trong file cho nó để làm việc.

Các vấn đề liên quan