有点像初学者的问题,但不幸的是搜索并没有帮助我。我在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)
我究竟做错了什么?