Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge Strategy in sbt assembly and missing application loader

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)

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
}
}

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

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?

like image 700
mox_mox Avatar asked Mar 21 '18 18:03

mox_mox


1 Answers

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 is a working example demonstrating the necessary configuration.

like image 78
Mario Galic Avatar answered Nov 13 '22 06:11

Mario Galic