使用可运行的 jar 运行 akka [英] Running akka with runnable jar
问题描述
我正在尝试使用 NetBeans 在 java maven 项目中实现 akka.当我从 NetBeans 运行它时它运行良好,但是当我从 NetBeans 运行可运行的 jar 时,它会产生错误.
I'm trying to implement akka in java maven project with NetBeans. It runs fine when i run it from NetBeans but when I run the runnable jar from NetBeans, it generate error.
Exception in thread "main" com.typesafe.config.ConfigException$Missing: No configuration setting found for key 'akka.remote.log-received-messages'
当我在配置中添加 log-received-message 时,它要求另一个配置.这是我用来生成 jar 文件的插件.
When I add log-received-message in the configuration, it ask for another configuration. This is the plugin that i used to generate the jar file.
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
我的依赖是
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.10</artifactId>
<version>2.3.7</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-remote_2.10</artifactId>
<version>2.3.7</version>
</dependency>
akka 的配置是
akka10300{
akka{
actor{provider = "akka.remote.RemoteActorRefProvider"}
remote {
enabled-transports = ["akka.remote.netty.tcp"]
netty.tcp {
hostname="127.0.0.1"
port=10300
}
}
}
}
推荐答案
http://doc.akka.io/docs/akka/snapshot/general/configuration.html.问题是有多个 reference.conf
配置文件,Maven 程序集或 shade 插件的默认行为是用后面的实例覆盖配置文件的早期实例.
There is a warning about running Akka from a "fat jar" at http://doc.akka.io/docs/akka/snapshot/general/configuration.html. The issue is that there are multiple reference.conf
configuration files, and the default behaviour of the Maven assembly or shade plugins is to overwrite earlier instances of the configuration file with later instances.
要解决此问题,建议的方法是使用 Maven shade 插件生成可执行 jar 并将其配置为将所有 resource.conf
文件附加到单个文件中而不是覆盖.建议的 Maven shade 插件配置如下所示:
To fix this, the suggested approach is to use the Maven shade plugin to generate your executable jar and configure it to append all resource.conf
files into a single file instead of overwriting. The suggested Maven shade plugin configuration looks like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>allinone</shadedClassifierName>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>akka.Main</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
这篇关于使用可运行的 jar 运行 akka的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!