Issue when building with SBT/assembly - Missing classes from xnio-nio at run-time.
Closed this issue · 1 comments
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.
This doesn't seem to be an issue with Mill. When I run an example project, it is able to start and I can access the website just fine:
First shell
$ wget https://github.com/com-lihaoyi/cask/releases/download/0.9.1/minimalApplication-0.9.1.zip
--2024-01-14 08:03:43-- https://github.com/com-lihaoyi/cask/releases/download/0.9.1/minimalApplication-0.9.1.zip
lihaoyi test$ unzip minimalApplication-0.9.1.zip
lihaoyi test$ cd minimalApplication-0.9.1
lihaoyi minimalApplication-0.9.1$ ./mill show app.assembly
"ref:9269ba96:/Users/lihaoyi/test/minimalApplication-0.9.1/out/app/assembly.dest/out.jar"
lihaoyi minimalApplication-0.9.1$ /Users/lihaoyi/test/minimalApplication-0.9.1/out/app/assembly.dest/out.jar
Another shell
lihaoyi ~$ curl localhost:8080
Hello World!%
Maybe something funny with the SBT config you're using, SBT-assembly, or SBT itself?