原因:com.typesafe.config.ConfigException$丢失

原因:com.typesafe.config.ConfigException$丢失,exception,akka,Exception,Akka,当我在Idea中运行我的应用程序时,它是好的。但是当我在linux中打包并运行java-jar时。我得到了这个例外。 问题代码是 val config = ConfigFactory.parseFile(new File("src/main/resources/master.conf")) master = context.actorSelection(s"akka.tcp://masterSystem@${config.getString("

当我在Idea中运行我的应用程序时,它是好的。但是当我在linux中打包并运行java-jar时。我得到了这个例外。

问题代码是

val config = ConfigFactory.parseFile(new File("src/main/resources/master.conf"))

    master = context.actorSelection(s"akka.tcp://masterSystem@${config.getString("akka.remote.netty.tcp.hostname")}:${config.getString("akka.remote.netty.tcp.port")}/user/Master")


src/main/resources
路径在jar中不存在,这是经过设计的

首先尝试在代码中获取配置,如下所示:

val config=ConfigFactor.load()


然后将
java-Dconfig.location=master.conf jar…
传递给您的程序,原因是:com.typesafe.config.ConfigException$丢失:在com.typesafe.config.impl.SimpleConfig.findKeyOrNull(SimpleConfig.java:156)在com.typesafe.config.impl.SimpleConfig.findKey(SimpleConfig.java:149)中找不到键“akka”的配置设置在com.typesafe.config.impl.SimpleConfig.findOrNull(SimpleConfig.java:176)在com.typesafe.config.impl.SimpleConfig.find(SimpleConfig.java:188)在com.typesafe.config.impl.SimpleConfig.getString(SimpleConfig.java:250)在com.hxdi.server.Worker.Prestar(Worker.scala:26)上