gpt4 book ai didi

java - Servlet异常: Method threw 'java.lang.NoClassDefFoundError'

转载 作者:行者123 更新时间:2023-12-02 06:06:57 25 4
gpt4 key购买 nike

我正在我的 Java EE Maven 项目中使用这个库:https://github.com/bertrandmartel/speed-test-lib

我收到以下异常 java.lang.ClassNotFoundException: fr.bmartel.speedtest.inter.ISpeedTestListener from [Module "deployment.vp_speedometer_war_exploded.war:main"from Service Module Loader]

我创建这个类:

 public class SpeedTest {

public SpeedTest() {
speedTestSocket = new SpeedTestSocket();
}

public void start() {
//set timeout for download
speedTestSocket.setSocketTimeout(SOCKET_TIMEOUT);

// add a listener to wait for speed examples completion and progress
speedTestSocket.addSpeedTestListener(new ISpeedTestListener() {
public void onProgress(final float percent, final SpeedTestReport downloadReport) {
transfertRateBitSecond = downloadReport.getTransferRateBit(); // + " bit/second";
}
});

speedTestSocket.startDownload(SPEED_TEST_SERVER_URI_DL);
}

我的 Servlet 看起来像:

public class Servlet extends HttpServlet {

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();

SpeedTest speedTest = new SpeedTest();
speedTest.start();

session.setAttribute("nbr", speedTest.getTransfertRateBitSecond());
response.sendRedirect("index.jsp");
}
}

它在SpeedTest speedTest = new SpeedTest();处抛出异常但我找不到解决办法...

root cause

java.lang.NoClassDefFoundError: fr/bmartel/speedtest/inter/ISpeedTestListener
ctrl.Servlet.doGet(Servlet.java:22)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

root cause

java.lang.ClassNotFoundException: fr.bmartel.speedtest.inter.ISpeedTestListener from [Module "deployment.vp_speedometer_war_exploded.war:main" from Service Module Loader]
org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
ctrl.Servlet.doGet(Servlet.java:22)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

感谢您的帮助

<小时/>

编辑

这是我的 pom.xml

<groupId>ch</groupId>
<artifactId>speedometer</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<!-- https://github.com/bertrandmartel/speed-test-lib -->
<dependency>
<groupId>fr.bmartel</groupId>
<artifactId>jspeedtest</artifactId>
<version>1.32.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webXml>web\WEB-INF\web.xml</webXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

当我构建项目时,“war”内部有我的“jspeedtest-1.13.1.jar”库。没关系

最佳答案

我觉得问题正在进展。当我尝试访问我的应用程序时,我得到了这个...

  13:04:21,652 WARN  [org.jboss.modules] (MSC service thread 1-15) Failed to define class ctrl.Servlet in Module "deployment.speedometer-1.0-SNAPSHOT.war:main" from Service Module Loader: java.lang.UnsupportedClassVersionError: ctrl/Servlet : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method) [rt.jar:1.7.0_79]
at java.lang.ClassLoader.defineClass(ClassLoader.java:800) [rt.jar:1.7.0_79]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [rt.jar:1.7.0_79]
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:327)

关于java - Servlet异常: Method threw 'java.lang.NoClassDefFoundError' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55936337/

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