gpt4 book ai didi

java - NoClassDefFoundError : Tomcat 7 unable to load classes from jar

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:08:54 25 4
gpt4 key购买 nike

有点初学者的问题,但不幸的是搜索对我没有帮助。我在 java 中创建了一个模拟 dieroll 的简单类,如下所示:

package java.com.game.util;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Dice {

private static Random randomGenerator = new Random();

public static int rollOne(){
return randomGenerator.nextInt(6)+1;
}

public static List<Integer> roll(int amountOfDice){
List<Integer> rolls = new ArrayList<Integer>();
for (int i = amountOfDice ; i > 0; i--){
rolls.add(rollOne());
}
return rolls;
}

}

之所以用“java”打包,是因为maven。 Dice.class 包含在 WEB-INF/lib 目录下的 Game-0.1-SNAPSHOT.jar 中。

我正在尝试在以下 jsp 中使用 Dice:

<H1>Test</H1>
<%= java.com.game.util.Dice.rollOne() %>

这是发生的错误:

org.apache.jasper.JasperException: An exception occurred processing JSP page /game/index.jsp at line 2

1: <H1>Some Heading</H1>
2: <%= java.com.game.util.Dice.rollOne() %>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:455)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

root cause

javax.servlet.ServletException: java.lang.NoClassDefFoundError: java/com/game/util/Dice
org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:912)
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:841)
org.apache.jsp.game.index_jsp._jspService(index_jsp.java:69)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

root cause

java.lang.NoClassDefFoundError: java/com/game/util/Dice
org.apache.jsp.game.index_jsp._jspService(index_jsp.java:63)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)

我做错了什么?

最佳答案

这是预期的 Tomcat 7 行为。一些打包被Tomcat限制了。您可以在以下位置找到无法加载的包/类列表

$CATALINA_BASE/conf/catalina.properties

java. 模式。

关于java - NoClassDefFoundError : Tomcat 7 unable to load classes from jar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16947111/

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