[英]Java.lang.NoClassDefFoundError: org/eclipse/jetty/util/component/ContainerLifeCycle
I was writing a simple program to send requests to a certain api using java and i decided to use jetty-client for http request handling.I decided to use jetty-client-11.0.0 to do this but upon running a basic script I keep getting the java.lang.NoClassDeffoundError;我正在编写一个简单的程序来使用 java 向某个 api 发送请求,我决定使用 jetty-client 进行 http 请求处理。我决定使用 jetty-client-11.0.0 来执行此操作但是在运行基本脚本后我保留了获取 java.lang.NoClassDefoundError;
package currencyconverter;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
public class urler{
public static void main(String[] args) throws InterruptedException, ExecutionException, TimeoutException, IOException {
HttpClient httpClient = new HttpClient();
ContentResponse response = httpClient.GET("example.com");
System.out.println(response.toString());
}
}
then the error is;那么错误是;
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/jetty/util/component/ContainerLifeCycle
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at currencyconverter.urler.main(urler.java:12)
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.util.component.ContainerLifeCycle
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 10 more
I tried changing the version of jetty-client but it didn't seem to work ie from jetty-client 12.0.0.alpha3 to jetty-client 11.0.0 thinking that it was a version error and hoping that it would fix the issue but it didn't work.我尝试更改 jetty-client 的版本,但它似乎没有用,即从 jetty-client 12.0.0.alpha3 到 jetty-client 11.0.0 认为这是一个版本错误并希望它能解决问题但是它没有用。
Welcome to the community.欢迎来到社区。 The reason for this error is, that one dependency is transitive and is not referenced directly.这个错误的原因是,一个依赖是可传递的,没有被直接引用。 Either you need to include the dependency org.eclipse.jetty:jetty-util
directly (see maven coordinates here: mavencentral ), or you can use maven and use this pom:您需要直接包含依赖org.eclipse.jetty:jetty-util
(请参阅此处的 maven 坐标: mavencentral ),或者您可以使用maven并使用此 pom:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>stackoverflow</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>11.0.8</version>
</dependency>
</dependencies>
</project>
If you want to find out, if there are more transitive dependencies, and you have no maven, you would need to unzip the dependency jar files and check the META-INF
folder .如果你想知道,如果有更多的传递依赖,而你没有maven,你需要解压依赖jar文件并检查META-INF
文件夹。 It contains the pom.xml
which contains the necessary dependencies.它包含包含必要依赖项的pom.xml
。
If you use already maven, you can use the command mvn dependeny:tree
which will output all direct and transitive dependencies:如果您已经使用 maven,则可以使用命令mvn dependeny:tree
,它将输出所有直接和传递依赖项:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ stackoverflow ---
[INFO] com.stackoverflow:stackoverflow:jar:1.0-SNAPSHOT
[INFO] +- org.slf4j:slf4j-api:jar:2.0.5:compile
[INFO] +- org.slf4j:slf4j-simple:jar:2.0.5:compile
[INFO] \- org.eclipse.jetty:jetty-client:jar:11.0.8:compile
[INFO] +- org.eclipse.jetty:jetty-http:jar:11.0.8:compile
[INFO] | \- org.eclipse.jetty:jetty-util:jar:11.0.8:compile
[INFO] +- org.eclipse.jetty:jetty-io:jar:11.0.8:compile
[INFO] \- org.eclipse.jetty:jetty-alpn-client:jar:11.0.8:compile
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.