gpt4 book ai didi

java.lang.NoClassDefFoundError : com/typesafe/config/Config while running akka-quickstart-java in STS

转载 作者:行者123 更新时间:2023-12-02 12:49:43 24 4
gpt4 key购买 nike

我正在尝试运行 http://developer.lightbend.com/guides/akka-quickstart-java/Spring Tool Suite(eclipse)中提供的项目

文件如下:

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 clean install:输出是:

...
[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)
...

我到底缺少什么?

最佳答案

您缺少主要的 com.typesafe 依赖项。在 POM.xml 添加

<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.2.1</version>
</dependency>

java.lang.NoClassDefFoundError 主要是由于缺少依赖项/jar 造成的。希望有帮助

关于java.lang.NoClassDefFoundError : com/typesafe/config/Config while running akka-quickstart-java in STS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44645904/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com