简体   繁体   中英

Akka: missing akka.version

I have a scala project which I've been running fine inside IntelliJ with a Run/Debug configuration set to Application, and now I'd like to create a jar to run it using 'java -jar .jar'. This is a maven project, not SBT.

I have three modules, and the top module which includes all other modules has an reference.conf in the resources folder. It's a minimal application.conf, not a lot of settings. Another one of the modules has its own reference.conf.

I created an artifact based on my top module, and I build it to create a jar. When I execute it with java

Exception in thread "main" java.lang.ExceptionInInitializerError
    at com.se.pd.Main.main(Main.scala)
Caused by: com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.version'
    at com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:124)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:145)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:151)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:159)
    at com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:164)
    at com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:206)
    at akka.actor.ActorSystem$Settings.<init>(ActorSystem.scala:168)
    at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:504)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:141)
    at akka.actor.ActorSystem$.apply(ActorSystem.scala:118)
    at com.se.pd.ServiceMain$class.$init$(ServiceMain.scala:25)
    at com.se.pd.Main$.<init>(Main.scala:17)
    at com.se.pd.Main$.<clinit>(Main.scala)

When I unzip the file, I see the merged reference.conf in the root dir.

What am I missing? Do I need to do something specific when I create my ActorSystem? I tried deleting all of my config files and running with all defaults, and it still didn't work, although in that case the error changed from complaining about "akka.version" to complaining about "akka". So it feels liek somehow I'm just not loading the akka defaults?

I fixed it for my purposes, but it doesn't really clarify to me what the issue is. My fix (IntelliJ IDEA specific) was to change the artifact from:

"extract to target JAR"

to

"copy to output directory and link via manifest"

I suppose something gets lost when I create a big fat jar.

--

I just wanted to add a better solution to create a "fat jar" with maven. But I can't take credit , since it looks like the Akka page linked below by Zoltan now suggests the same solution, and in all honesty I cannot remember where I found this. I may have run into the updated page at some point in the past. Please consult that link for much better information.

So:

Use the maven shader plugin to create the fat jar Then make sure you merge the configuration files:

<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
          <resource>reference.conf</resource>
     </transformer>
     <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
      <mainClass>myMainClass</mainClass>
</transformer>

Using that configuration, I can successfully build fat jars.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM