Skip to content

Issue when building with SBT/assembly - Missing classes from xnio-nio at run-time. #104

@jrlemieux

Description

@jrlemieux

I am building my project with SBT and I have these dependencies and assembly rules that appear below.
When I run the program with this command, using my fat jar tts.jar, I get an exception:

java -cp tts.jar cc.lemieux.tts.Main server
java.lang.IllegalArgumentException("XNIO001001: No XNIO provider found") org.xnio.Xnio:261:178, io.undertow.Undertow:121, cask.main.Main:69

Somehow, some xnio-nio classes needed by undertow are not appended to the generated assembly.

The issue can be fixed by supplying two jar files in the classpath, such as:

java -Djava.net.preferIPv4Stack=true -Djava.net.preferIPv6Addresses=false -cp tts.jar:xnio-nio-3.8.7.Final.jar cc.lemieux.tts.Main server

Some lines from build.sbt

assembly / assemblyJarName := "tts.jar"

libraryDependencies ++= Seq(
  "com.amazonaws" % "aws-java-sdk-polly" % "1.12.87",
  "com.lihaoyi" %% "cask" % "0.9.1",
  "com.lihaoyi" %% "scalatags" % "0.12.0"
)

assembly / assemblyMergeStrategy := {
  case PathList("META-INF", xs @ _*) => MergeStrategy.discard
  case x                             => MergeStrategy.first
}

The name of the xnio-nio jar file to be appended to the class path can be found with this script. There might be a better way to achieve this, but here is what worked for me:

sbt clean assembly libraryDependencies >/tmp/lib.txt
cask_version=`grep '* com.lihaoyi:cask:' /tmp/lib.txt | cut -d: -f3`
rm /tmp/lib.txt
cask_pom=`find ~/.cache/coursier/ -name "cask_3-$cask_version.pom"`

undertow_version=`grep -A1 undertow-core $cask_pom | tail -1 | cut '-d>' -f2 | cut '-d<' -f1`
undertow_parent_pom=`find ~/.cache/coursier/ -name "undertow-parent-$undertow_version.pom"`

xnio_version=`grep '<version.xnio>' $undertow_parent_pom | cut '-d>' -f2 | cut '-d<' -f1`
xnio_nio_jar=`find ~/.cache/coursier/ -name "xnio-nio-$xnio_version.jar"`

echo "XNIO-NIO JAR: $xnio_nio_jar"

This is not a bug in Cask, but I would recommend that this issue should be documented because anyone building with SBT will likely hit it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions