2013-07-10 34 views
11

Bạn có thể cho tôi biết lý do tại sao sbt compile không sao chép tài nguyên không được quản lý sang classpath? Mặt khác, sbt package. Kết quả tôi không thể bắt đầu gỡ rối, trừ khi tôi gọi package gọi bằng tay :(Tại sao biên dịch sbt không sao chép tài nguyên không được quản lý sang classpath?

Tôi đang sử dụng SBT 0.12.1

Dưới đây là build.sbt tôi.

import AssemblyKeys._ // put this at the top of the file 

net.virtualvoid.sbt.graph.Plugin.graphSettings 

assemblySettings 

organization := "com.zzz" 

version  := "0.1" 

scalaVersion := "2.10.2" 

scalacOptions := Seq("-unchecked", "-language:reflectiveCalls,postfixOps,implicitConversions", "-deprecation", "-feature", "-encoding", "utf8") 

unmanagedResourceDirectories in Compile <++= baseDirectory { base => 
    Seq(base/"src/main/webapp") 
} 

jarName in assembly := "zzz.jar" 

mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) => 
    { 
     case "rootdoc.txt" => MergeStrategy.discard 
     case x => old(x) 
    } 
} 

mainClass in assembly := Some("com.zzz.Boot") 

name := "zzz" 

// disable using the Scala version in output paths and artifacts 
crossPaths := false 

artifactName := { (sv: ScalaVersion, module: ModuleID, artifact: Artifact) => 
    artifact.name + "." + artifact.extension 
} 

resolvers ++= Seq(
    "spray repo" at "http://repo.spray.io/" 
) 

libraryDependencies ++= { 
    val sprayVersion = "1.2-M8" 
    val akkaVersion = "2.2.0-RC1" 
Seq(
    "io.spray"   % "spray-servlet" % sprayVersion withSources(), 
    "io.spray"   % "spray-can"  % sprayVersion withSources(), 
    "io.spray"   % "spray-routing" % sprayVersion withSources(), 
    "com.typesafe.akka" %% "akka-actor" % akkaVersion, 
    "org.eclipse.jetty"  % "jetty-webapp" % "8.1.7.v20120910"  % "container", 
    "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container" artifacts Artifact("javax.servlet", "jar", "jar"), 
    "net.sourceforge.htmlcleaner" % "htmlcleaner" % "2.2", 
    "org.apache.httpcomponents" % "httpclient" % "4.2.3", 
    "org.apache.commons" % "commons-lang3" % "3.1", 
    "org.mongodb" %% "casbah" % "2.6.0", 
    "com.romix.scala" % "scala-kryo-serialization" % "0.2-SNAPSHOT", 
    "org.codehaus.jettison" % "jettison" % "1.3.3", 
    "com.osinka.subset" %% "subset" % "2.0.1", 
    "io.spray" %% "spray-json" % "1.2.5" intransitive() 
) 
} 

seq(Revolver.settings: _*) 

seq(webSettings: _*) 

seq(Twirl.settings: _*) 
+0

'Hiển thị biên dịch: không được quản lý-tài nguyên-thư mục' trả về những gì? – 4lex1v

+0

@AlexIv '[info] Danh sách (C: \ work \ sideprojects \ courierapp \ server \ src \ main \ resources, C: \ work \ sideprojects \ courierapp \ server \ src \ main \ webapp)' – expert

+1

Bạn không thể chỉ sử dụng 'src/main/resources/webapp' sẽ được bao gồm theo mặc định? –

Trả lời

16

Công việc của compile Tuy nhiên, các tài nguyên cần phải nằm trong thư mục lớp cho run, package, test, console và bất kỳ tài nguyên nào khác sử dụng số fullClasspath. fullClasspath kết hợp exportedProducts, là các lớp và tài nguyên được tạo bởi dự án hiện tại và dependencyClasspath, là các mục nhập classpath từ các phụ thuộc.

Giải pháp thích hợp tùy thuộc vào nhu cầu tài nguyên. Từ dòng lệnh, hãy chạy exported-products để thực hiện compile cũng như copy-resources. Theo lập trình, thông thường bạn sẽ muốn phụ thuộc vào fullClasspath hoặc exportedProducts.

Như một lưu ý phụ, bạn thường có thể tìm hiểu nhiệm vụ nào làm những gì sử dụng the inspect command.

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