将非托管资源复制到类路径

将非托管资源复制到类路径

本文介绍了为什么 sbt compile 不会将非托管资源复制到类路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

您能告诉我为什么 sbt compile 不将非托管资源复制到类路径吗?另一方面 sbt package 确实如此.因此,除非我手动调用 package 调用,否则我无法开始调试:(

Could you tell me why sbt compile doesn't copy unmanaged resources to classpath? On the other hand sbt package does. As result I can't start debugging unless I invoke package call manually :(

我使用的是 SBT 0.12.1

I'm using SBT 0.12.1

下面是我的 build.sbt.

Below is my build.sbt.

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: _*)

推荐答案

compile 的工作是编译源代码,因此它通常不会做任何与处理资源相关的事情.但是,资源需要在 runpackagetestconsole 和任何东西的类目录中其他使用 fullClasspath 的.这是通过 fullClasspath 结合 exportedProducts(当前项目生成的类和资源)和 dependencyClasspath(从依赖.

The job of compile is to compile sources, so it won't typically do anything related to processing resources. However, the resources need to be in the class directory for run, package, test, console, and anything else that uses the fullClasspath. This is done by fullClasspath combining exportedProducts, which are the classes and resources generated by the current project, and dependencyClasspath, which are the classpath entries from dependencies.

适当的解决方案取决于需要什么资源.从命令行,运行 exported-products 以执行 compile 以及 copy-resources.以编程方式,您通常希望依赖 fullClasspathexportedProducts.

The appropriate solution depends on what needs the resources. From the command line, run exported-products to do a compile as well as copy-resources. Programmatically, you will typically want to depend on fullClasspath or exportedProducts.

作为旁注,您通常可以使用inspect命令.

As a side note, you can typically find out what tasks do what using the inspect command.

这篇关于为什么 sbt compile 不会将非托管资源复制到类路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:26