0
我想在春天工具套件運行http://developer.lightbend.com/guides/akka-quickstart-java/ 提供的項目(日蝕)是java.lang.NoClassDefFoundError:COM /類型安全/配置/配置,同時運行在STS阿卡 - 快速入門的Java
文件如下:
1.AkkaQuickstart.java
import java.io.IOException;
import akka.actor.ActorRef;
import akka.actor.ActorSystem;
public class AkkaQuickstart {
public static void main(String[] args) {
final ActorSystem system = ActorSystem.create("helloakka");
try {
//#create-actors
final ActorRef printerActor =
system.actorOf(Printer.props(), "printerActor");
final ActorRef howdyGreeter =
system.actorOf(Greeter.props("Howdy", printerActor), "howdyGreeter");
final ActorRef helloGreeter =
system.actorOf(Greeter.props("Hello", printerActor), "helloGreeter");
final ActorRef goodDayGreeter =
system.actorOf(Greeter.props("Good day", printerActor), "goodDayGreeter");
//#create-actors
//#main-send-messages
howdyGreeter.tell(new WhoToGreet("Akka"), ActorRef.noSender());
howdyGreeter.tell(new Greet(), ActorRef.noSender());
howdyGreeter.tell(new WhoToGreet("Lightbend"), ActorRef.noSender());
howdyGreeter.tell(new Greet(), ActorRef.noSender());
helloGreeter.tell(new WhoToGreet("Java"), ActorRef.noSender());
helloGreeter.tell(new Greet(), ActorRef.noSender());
goodDayGreeter.tell(new WhoToGreet("Play"), ActorRef.noSender());
goodDayGreeter.tell(new Greet(), ActorRef.noSender());
//#main-send-messages
System.out.println(">>> Press ENTER to exit <<<");
System.in.read();
} catch (IOException ioe) {
} finally {
system.terminate();
}
}
}
2.Greeter.java
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.Props;
//#greeter-messages
public class Greeter extends AbstractActor {
//#greeter-messages
static public Props props(String message, ActorRef printerActor) {
return Props.create(Greeter.class,() -> new Greeter(message, printerActor));
}
//#greeter-messages
static public class WhoToGreet {
public final String who;
public WhoToGreet(String who) {
this.who = who;
}
}
static public class Greet {
public Greet() {
}
}
//#greeter-messages
private final String message;
private final ActorRef printerActor;
private String greeting = "";
public Greeter(String message, ActorRef printerActor) {
this.message = message;
this.printerActor = printerActor;
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(WhoToGreet.class, wtg -> {
this.greeting = message + ", " + wtg.who;
})
.match(Greet.class, x -> {
//#greeter-send-message
printerActor.tell(new Greeting(greeting), getSelf());
//#greeter-send-message
})
.build();
}
//#greeter-messages
}
//#greeter-messages
3.Printer.java
import akka.actor.AbstractActor;
import akka.actor.Props;
import akka.event.Logging;
import akka.event.LoggingAdapter;
//#printer-messages
public class Printer extends AbstractActor {
//#printer-messages
static public Props props() {
return Props.create(Printer.class,() -> new Printer());
}
//#printer-messages
static public class Greeting {
public final String message;
public Greeting(String message) {
this.message = message;
}
}
//#printer-messages
private LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
public Printer() {
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(Greeting.class, greeting -> {
log.info(greeting.message);
})
.build();
}
//#printer-messages
}
//#printer-messages
4.pom.xml
<!-- #build-sample -->
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>hello-akka-java</groupId>
<artifactId>app</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.12</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-testkit_2.12</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>com.lightbend.akka.sample.AkkaQuickstart</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</project>
我試圖運行Maven構建:MVN全新安裝: 輸出是:
...
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ app ---
[INFO] Surefire report directory: /Users/xxx/Downloads/akka-quickstart-java/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.lightbend.akka.sample.AkkaQuickstartTest
Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.555 sec <<< FAILURE!
com.lightbend.akka.sample.AkkaQuickstartTest Time elapsed: 0.555 sec <<< ERROR!
java.lang.BootstrapMethodError: java.lang.NoClassDefFoundError: com/typesafe/config/Config
at akka.actor.ActorSystem$.apply(ActorSystem.scala:241)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:287)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:232)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:223)
at akka.actor.ActorSystem$.create(ActorSystem.scala:158)
at akka.actor.ActorSystem.create(ActorSystem.scala)
at com.lightbend.akka.sample.AkkaQuickstartTest.setup(AkkaQuickstartTest.java:20)
...
我在這裏錯過了什麼?
我創建從http://dev.lightbend.com/start/?group=akka&project=akka-quickstart-java項目 - 這是快速啓動阿卡在eclipse – virsha
您是否嘗試過加入官方網站上面的依賴關係? – Akshay
是的,它的工作 – virsha