2

I am creating a simple akka cluster with ClusterActorRefProvider using netty. Everything is working fine when I run the code from idea. But, all of a sudden everything fails when I run the application as jar. It is throwing an error "No configuration setting found for key 'akka.remote.artery'". I am creating the jar using sbt assembly.

What am I missing here? Any help please....

ArunavaS
  • 197
  • 1
  • 12
  • Please let me know if you need any more detail... – ArunavaS May 29 '17 at 09:39
  • Seems like application.conf file is absent in your jar. Could you list jar contents? You may use `jar tf your.jar` for it. – Evgeny Veretennikov May 29 '17 at 12:04
  • Looks like you're using akka-remote (with artery) => http://doc.akka.io/docs/akka/current/scala/remoting-artery.html – mfirry May 29 '17 at 14:44
  • Hi Evgeny, application is parsing jar as I did some print on the config params and they are getting printed as expected. However, when I did jar tf I could find application.conf in the list... – ArunavaS May 30 '17 at 06:23
  • Hi Mfirry, my sbt contains akka-remote... Shall I remove the dependency? I am using clusterSharding using "ClusterActorRefProvider". Please let me know if remote is still needed... – ArunavaS May 30 '17 at 06:25
  • Update guys, I printed out 'akka.remote.artery' and it took the default settings with enabled=off when I run from ide... – ArunavaS May 30 '17 at 06:37
  • Used MergeStrategy.concat, but now am getting an weird error - "java.lang.ClassFormatError: Extra bytes at the end of class file"... Can anyone help me here please? reference.conf is properly getting generated with default artery configuration now. – ArunavaS May 30 '17 at 10:34

2 Answers2

7

solved using below lines in build.sbt

assemblyMergeStrategy in assembly := {
   case PathList("META-INF", xs @ _*) => MergeStrategy.discard
   case "reference.conf" => MergeStrategy.concat
   case x => MergeStrategy.first
}
ArunavaS
  • 197
  • 1
  • 12
2

I ran into a similar issue when packaging an Akka application as a far JAR with all the dependencies merged together, using the Maven assembly plugin instead of SBT.

The underlying issue lies because when packaging a fat JAR, files which reside in the same path (e.g. /reference.conf) are overwritten by the build system by default. Thus, when using multiple Akka modules, one reference.conf will end up overwriting all the others, thus you will end up with a single, partial reference.conf in your JAR file, instead of multiple reference.conf which are then merged by the config library when it loads them.

This causes the no configuration found errors, because the default configuration settings for some modules (as found in their reference.conf which was overwritten) are missing.

@ArunavaS answer works for SBT, since it merges the reference.conf files. If using Maven, then it is possible to configure it to do something similar (e.g. see How can I merge resource files in a Maven assembly?).

Alternatively, instead of using a fat JAR, you can export all the dependencies to a separate folder, and then add them to the classpath when running the JAR file.

Daniel
  • 383
  • 3
  • 13