简体   繁体   English

Akka:缺少akka.version

[英]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'. 我有一个scala项目,我在IntelliJ中运行良好,运行/调试配置设置为Application,现在我想创建一个jar来使用'java -jar .jar'来运行它。 This is a maven project, not SBT. 这是一个maven项目,而不是SBT。

I have three modules, and the top module which includes all other modules has an reference.conf in the resources folder. 我有三个模块,包含所有其他模块的顶层模块在resources文件夹中有一个reference.conf。 It's a minimal application.conf, not a lot of settings. 这是一个最小的application.conf,而不是很多设置。 Another one of the modules has its own reference.conf. 另一个模块有自己的reference.conf。

I created an artifact based on my top module, and I build it to create a jar. 我基于我的顶层模块创建了一个工件,我构建它来创建一个jar。 When I execute it with java 当我用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. 当我解压缩文件时,我在根目录中看到合并的reference.conf。

What am I missing? 我错过了什么? Do I need to do something specific when I create my ActorSystem? 我在创建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". 我尝试删除所有配置文件并使用所有默认值运行,但仍然无法正常工作,尽管在这种情况下错误从抱怨“akka.version”变为抱怨“akka”。 So it feels liek somehow I'm just not loading the akka defaults? 所以我觉得谎言我只是不加载akka默认值?

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: 我的修复(IntelliJ IDEA特定)是从以下更改工件:

"extract to target JAR" “提取到目标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. 我只想添加一个更好的解决方案来创建一个带有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. 但是我不能相信 ,因为看起来Zoltan下面链接的Akka页面现在提出了相同的解决方案,并且说实话,我不记得我在哪里发现了这个。 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: 使用maven着色器插件创建胖jar然后确保合并配置文件:

<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. 使用该配置,我可以成功构建胖罐。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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