sbt组装中的合并策略和缺少应用程序加载器 [英] Merge Strategy in sbt assembly and missing application loader

查看:142
本文介绍了sbt组装中的合并策略和缺少应用程序加载器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Play web app that I am working on and I would like to be able to deploy it as a fat jar using sbt assembly. While running the application in debug i have no problems with guice library being recognized as it is added in my build.sbt file: libraryDependencies += guice. I have created my sbt assembly MergeStrategy configuration and ran sbt assembly and successfully compiled the jar file for the project, However when i attempt to run the jar i get the following Exception in console:

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文件:

and here is my build.sbt file:

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造成的吗?或者是别的什么?在下面,我还列出了合并文件的列表以及在有帮助的情况下应用的合并策略.

Since i have already added guice I am not sure what has happened or how to fix this. could this possibly be due to an incorrect MergeStrategy? Or is it something else? Below I am also including the list of files merged and merge strategies applied in case this is of any help.

[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.如果这两个罐子引起冲突,应该如何解决?取出罐子?或修改合并策略?还有其他提示可能是什么问题的线索吗?

this line was also included: [info] Including from cache: play-guice_2.12-2.6.12.jar and this one as well [info] Including from cache: guice-4.1.0.jar. If these two jars are causing conflict how should this be resolved? remove jar? or modify merge strategy? Any other clues to what the problem could be?

推荐答案

播放

Play documents the following merge strategy to be used with sbt-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 是一个演示必要配置的工作示例.

play-scala-sbt-assembly-example is a working example demonstrating the necessary configuration.

这篇关于sbt组装中的合并策略和缺少应用程序加载器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆