【问题标题】:Merge Strategy in sbt assembly and missing application loadersbt 程序集中的合并策略和缺少应用程序加载器
【发布时间】:2018-08-31 01:11:54
【问题描述】:

我有一个正在开发的 Play 网络应用程序,我希望能够使用 sbt 程序集将其部署为胖 jar。在调试中运行应用程序时,我没有识别 guice 库的问题,因为它已添加到我的 build.sbt 文件中:libraryDependencies += guice。我已经创建了我的 sbt 程序集 MergeStrategy 配置并运行了 sbt 程序集并成功编译了项目的 jar 文件,但是当我尝试运行 jar 时,我在控制台中收到以下异常:

Oops, cannot start the server.
java.lang.RuntimeException: No application loader is configured. Please 
configure an application loader either using the play.application.loader 
configuration property, or by depending on a module that configures one. You 
can add the Guice support module by adding "libraryDependencies += guice" to 
your build.sbt.
    at scala.sys.package$.error(package.scala:27)
    at play.api.ApplicationLoader$.play$api$ApplicationLoader$$loaderNotFound(ApplicationLoader.scala:44)
    at play.api.ApplicationLoader$.apply(ApplicationLoader.scala:70)
    at play.core.server.ProdServerStart$.start(ProdServerStart.scala:50)
    at play.core.server.ProdServerStart$.main(ProdServerStart.scala:25)
    at play.core.server.ProdServerStart.main(ProdServerStart.scala)

这是我的 build.sbt 文件:

name := """Product-Inventory"""
organization := "com.example"

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.12.3"

//libraryDependencies += Defaults.sbtPluginExtra("com.eed3si9n" % "sbt-assembly" % "0.7.4", "0.12.0-M2", "2.9.1")

// https://mvnrepository.com/artifact/net.ruippeixotog/scala-scraper
libraryDependencies += "net.ruippeixotog" %% "scala-scraper" % "2.0.0"


libraryDependencies += guice //GUICE IS ADDED HERE
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "3.1.2" % Test

libraryDependencies += "org.scala-lang.modules" %% "scala-async" % "0.9.7"

libraryDependencies += jdbc
libraryDependencies += "postgresql" % "postgresql" % "9.1-901.jdbc4"

// Adds additional packages into Twirl
//TwirlKeys.templateImports += "com.example.controllers._"

// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "com.example.binders._"

mainClass in assembly := Some("play.core.server.ProdServerStart")
fullClasspath in assembly += 
Attributed.blank(PlayKeys.playPackageAssets.value)

assemblyMergeStrategy in assembly := {

  case PathList("META-INF", xs @ _*) => MergeStrategy.discard
  case referenceOverrides if referenceOverrides.contains("reference-
overrides.conf") => MergeStrategy.concat
case PathList("reference-overrides.conf") => MergeStrategy.concat
case x => {
MergeStrategy.first
}
}

由于我已经添加了 guice,我不确定发生了什么或如何解决这个问题。这可能是由于不正确的 MergeStrategy 造成的吗?或者是别的什么?下面我还包括合并的文件列表和应用的合并策略,以防万一这有任何帮助。

[info] Merging files...
[warn] Merging 'META-INF\CHANGES' with strategy 'discard'
[warn] Merging 'META-INF\COPYRIGHT.html' with strategy 'discard'
[warn] Merging 'META-INF\DEPENDENCIES' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_commons-codec-1.10.txt' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_commons-io-2.5.txt' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_commons-lang3-3.6.txt' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_commons-logging-1.2.txt' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_guice-4.1.0' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_guice-assistedinject-4.1.0' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_httpclient-4.5.3' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_httpcore-4.4.6' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_httpmime-4.5.3' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_jackson-annotations-2.8.11' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_jackson-core-2.8.11' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_jackson-databind-2.8.11' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_jackson-datatype-jsr310-2.8.11' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_joda-convert-1.2.txt' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_joda-time-2.9.9.txt' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_jsoup-1.10.2' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_jta-1.1.txt' with strategy 'discard'
[warn] Merging 'META-INF\LICENSE_xercesImpl-2.11.0' with strategy 'discard'
[warn] Merging 'META-INF\MANIFEST.MF' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_commons-codec-1.10.txt' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_commons-io-2.5.txt' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_commons-lang3-3.6.txt' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_commons-logging-1.2.txt' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_guice-4.1.0' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_guice-assistedinject-4.1.0' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_httpclient-4.5.3' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_httpcore-4.4.6' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_httpmime-4.5.3' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_jackson-core-2.8.11' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_jackson-databind-2.8.11' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_joda-convert-1.2.txt' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_joda-time-2.9.9.txt' with strategy 'discard'
[warn] Merging 'META-INF\NOTICE_xercesImpl-2.11.0' with strategy 'discard'
[warn] Merging 'META-INF\README_jsoup-1.10.2' with strategy 'discard'
[warn] Merging 'META-INF\maven\cglib\cglib\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\cglib\cglib\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\ch.qos.logback\logback-classic\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\ch.qos.logback\logback-classic\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\ch.qos.logback\logback-core\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\ch.qos.logback\logback-core\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.core\jackson-annotations\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.core\jackson-annotations\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.core\jackson-core\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.core\jackson-core\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.core\jackson-databind\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.core\jackson-databind\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.datatype\jackson-datatype-jdk8\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.datatype\jackson-datatype-jdk8\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.datatype\jackson-datatype-jsr310\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.fasterxml.jackson.datatype\jackson-datatype-jsr310\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.google.errorprone\error_prone_annotations\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.google.errorprone\error_prone_annotations\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.google.guava\guava\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.google.guava\guava\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.google.j2objc\j2objc-annotations\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.google.j2objc\j2objc-annotations\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.googlecode.usc\jdbcdslog\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.googlecode.usc\jdbcdslog\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.jolbox\bonecp\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.jolbox\bonecp\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.zaxxer\HikariCP\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\com.zaxxer\HikariCP\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\commons-codec\commons-codec\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\commons-codec\commons-codec\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\commons-io\commons-io\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\commons-io\commons-io\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\commons-logging\commons-logging\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\commons-logging\commons-logging\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\io.jsonwebtoken\jjwt\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\io.jsonwebtoken\jjwt\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\joda-time\joda-time\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\joda-time\joda-time\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\net.sourceforge.cssparser\cssparser\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\net.sourceforge.cssparser\cssparser\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\net.sourceforge.htmlunit\htmlunit\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\net.sourceforge.htmlunit\htmlunit\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\net.sourceforge.htmlunit\neko-htmlunit\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\net.sourceforge.htmlunit\neko-htmlunit\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.apache.commons\commons-lang3\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.apache.commons\commons-lang3\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.apache.httpcomponents\httpclient\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.apache.httpcomponents\httpclient\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.apache.httpcomponents\httpcore\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.apache.httpcomponents\httpcore\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.apache.httpcomponents\httpmime\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.apache.httpcomponents\httpmime\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.codehaus.mojo\animal-sniffer-annotations\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.codehaus.mojo\animal-sniffer-annotations\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty.websocket\websocket-api\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty.websocket\websocket-api\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty.websocket\websocket-client\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty.websocket\websocket-client\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty.websocket\websocket-common\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty.websocket\websocket-common\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty\jetty-client\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty\jetty-client\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty\jetty-http\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty\jetty-http\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty\jetty-io\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty\jetty-io\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty\jetty-util\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.eclipse.jetty\jetty-util\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.joda\joda-convert\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.joda\joda-convert\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.jsoup\jsoup\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.jsoup\jsoup\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.slf4j\jcl-over-slf4j\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.slf4j\jcl-over-slf4j\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.slf4j\jul-to-slf4j\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.slf4j\jul-to-slf4j\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.slf4j\slf4j-api\pom.properties' with strategy 'discard'
[warn] Merging 'META-INF\maven\org.slf4j\slf4j-api\pom.xml' with strategy 'discard'
[warn] Merging 'META-INF\resources\webjars\product-inventory\1.0-SNAPSHOT\javascripts\main.js' with strategy 'discard'
[warn] Merging 'META-INF\resources\webjars\product-inventory\1.0-SNAPSHOT\stylesheets\bootstrap.min.css' with strategy 'discard'
[warn] Merging 'META-INF\resources\webjars\product-inventory\1.0-SNAPSHOT\stylesheets\main.css' with strategy 'discard'
[warn] Merging 'META-INF\services\com.fasterxml.jackson.core.JsonFactory' with strategy 'discard'
[warn] Merging 'META-INF\services\com.fasterxml.jackson.core.ObjectCodec' with strategy 'discard'
[warn] Merging 'META-INF\services\com.fasterxml.jackson.databind.Module' with strategy 'discard'
[warn] Merging 'META-INF\services\java.sql.Driver' with strategy 'discard'
[warn] Merging 'META-INF\services\javax.servlet.ServletContainerInitializer' with strategy 'discard'
[warn] Merging 'META-INF\services\javax.xml.datatype.DatatypeFactory' with strategy 'discard'
[warn] Merging 'META-INF\services\javax.xml.parsers.DocumentBuilderFactory' with strategy 'discard'
[warn] Merging 'META-INF\services\javax.xml.parsers.SAXParserFactory' with strategy 'discard'
[warn] Merging 'META-INF\services\javax.xml.stream.XMLEventFactory' with strategy 'discard'
[warn] Merging 'META-INF\services\javax.xml.transform.TransformerFactory' with strategy 'discard'
[warn] Merging 'META-INF\services\javax.xml.validation.SchemaFactory' with strategy 'discard'
[warn] Merging 'META-INF\services\javax.xml.xpath.XPathFactory' with strategy 'discard'
[warn] Merging 'META-INF\services\org.apache.commons.logging.LogFactory' with strategy 'discard'
[warn] Merging 'META-INF\services\org.apache.xalan.extensions.bsf.BSFManager' with strategy 'discard'
[warn] Merging 'META-INF\services\org.apache.xml.dtm.DTMManager' with strategy 'discard'
[warn] Merging 'META-INF\services\org.eclipse.jetty.http.HttpFieldPreEncoder' with strategy 'discard'
[warn] Merging 'META-INF\services\org.eclipse.jetty.websocket.api.extensions.Extension' with strategy 'discard'
[warn] Merging 'META-INF\services\org.w3c.dom.DOMImplementationSourceList' with strategy 'discard'
[warn] Merging 'META-INF\services\org.xml.sax.driver' with strategy 'discard'
[warn] Merging 'org\apache\commons\logging\Log.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\LogConfigurationException.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\LogFactory.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\impl\NoOpLog.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\impl\SimpleLog$1.class' with strategy 'first'
[warn] Merging 'org\apache\commons\logging\impl\SimpleLog.class' with strategy 'first'
[warn] Merging 'play\reference-overrides.conf' with strategy 'concat'
[warn] Merging 'reference.conf' with strategy 'first'
[warn] Strategy 'concat' was applied to a file
[warn] Strategy 'discard' was applied to 137 files
[warn] Strategy 'first' was applied to 7 files
[info] Assembly up to date: C:\Users\zemcd\Extras\Play_Apps\product-inventory\target\scala-2.12\Product-Inventory-assembly-1.0-SNAPSHOT.jar
[success] Total time: 15 s, completed Mar 21, 2018 11:19:27 AM

这一行也包括在内:[info] Including from cache: play-guice_2.12-2.6.12.jar 和这一行以及[info] Including from cache: guice-4.1.0.jar。如果这两个罐子引起冲突,应该如何解决?删除罐子?或修改合并策略?有什么其他线索可以说明问题可能是什么?

【问题讨论】:

  • 这可能是 sbt-assembly 中的缓存问题。尝试禁用它:github.com/sbt/sbt-assembly#caching
  • @laughedelic 我尝试像 assemblyOption in assembly := (assemblyOption in assembly).value.copy(cacheUnzip = false) 这样禁用缓存,但我仍然遇到同样的问题。
  • @mox_mox 这个问题好像很久以前就有人问过了,但你有没有找到解决办法?我遇到了同样的问题。
  • @JoeC 我遇到了同样的问题,如果您找到解决方案,请分享。

标签: scala playframework sbt sbt-assembly


【解决方案1】:

播放documentssbt-assembly 一起使用的以下合并策略:

assemblyMergeStrategy in assembly := {
  case manifest if manifest.contains("MANIFEST.MF") =>
    // We don't need manifest files since sbt-assembly will create
    // one with the given settings
    MergeStrategy.discard
  case referenceOverrides if referenceOverrides.contains("reference-overrides.conf") =>
    // Keep the content for all reference-overrides.conf files
    MergeStrategy.concat
  case x =>
    // For all the other files, use the default sbt-assembly merge strategy
    val oldStrategy = (assemblyMergeStrategy in assembly).value
    oldStrategy(x)
}

play-scala-sbt-assembly-example 是一个演示必要配置的工作示例。

【讨论】:

    【解决方案2】:

    看起来 Play 有自己的 dist 函数,该函数在后台使用 sbt 本机打包程序插件。按照此处的说明,我能够让我的程序正常工作:https://www.playframework.com/documentation/2.7.x/Deploying#Using-the-dist-task

    【讨论】:

      【解决方案3】:

      对于 Play 2.8,唯一对我有用的解决方案是 official solution 的变体:

      assembly / assemblyMergeStrategy := {
        // otherwise basic settings are missing
        // e.g. missing play.server.http.port and play.server.dir
        case r if r.startsWith("reference.conf")          => MergeStrategy.concat
        case manifest if manifest.contains("MANIFEST.MF") =>
          // We don't need manifest files since sbt-assembly will create
          // one with the given settings
          MergeStrategy.discard
        case referenceOverrides
            if referenceOverrides.contains("reference-overrides.conf") =>
          // Keep the content for all reference-overrides.conf files
          MergeStrategy.concat
        case x => MergeStrategy.first
      // leads to "deduplicate: different file contents found in the following" errors:
      //  case x =>
      //    // For all the other files, use the default sbt-assembly merge strategy
      //    val oldStrategy = (assembly / assemblyMergeStrategy).value
      //    oldStrategy(x)
      }
      

      【讨论】:

        猜你喜欢
        • 2013-01-25
        • 2020-06-27
        • 1970-01-01
        • 2016-09-18
        • 2014-09-17
        • 1970-01-01
        • 1970-01-01
        • 2023-04-08
        • 2016-01-09
        相关资源
        最近更新 更多