• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError Problem with running a jasper report

 
raghav shukla
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am facing NoClassDefFound when the following servlet is called.. what could be the reason ??? please help

package testjasper;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;
import net.sf.jasperreports.engine.JasperRunManager;

public class DoJasper extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{

String username="";
String password="";
String url = "jdbcdbc:TestDB";
Connection con=null;

Map param = new HashMap();


//----CREATE CONNECTION----//
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") ;
con = DriverManager.getConnection(url, username, password);
System.out.print("Connection Created");

}
catch(SQLException e){
e.getMessage();
}
catch(ClassNotFoundException e1){
e1.getMessage();
}

//----CREATE OUTPUT STREAM FOR SENDING "application/pdf" TYPE DATA TO THE RESPONSE----//

response.setContentType("application/pdf");
ServletOutputStream out = response.getOutputStream();

//----COMPILING JRXML FILE----//

try{
JasperCompileManager.compileReportToFile("D:\\OTHER\\Raghav\\MyTestJRXML.jrxml"); //here is the problem
}catch(JRException j){
j.getMessage();
}

//----CREATING INPUT STREAM FOR READING .jasper FILE----//
InputStream is = getServletConfig().getServletContext().getResourceAsStream("D:/OTHER/Raghav/MyTestJRXML.jasper");

//----CONVERT REPORT TO PDF AND WRAP IT IN AN OUTPUT STREAM THAT WRITES TO THE RESPONSE----//

try {
JasperRunManager.runReportToPdfStream(is, out, param, con);
} catch (JRException e1) {
e1.printStackTrace();
}
try {
con.close();
} catch (SQLException e){
e.printStackTrace();
}
out.flush();
out.close();
}
}

Here is my web.xml

?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>DoJasper</servlet-name>
<servlet-class>testjasper.DoJasper</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>DoJasper</servlet-name>
<url-pattern>/GetReport</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>



here is teh complete detail of the error

SEVERE: Servlet.service() for servlet DoJasper threw exception
java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester
at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:89)
at testjasper.DoJasper.doGet(DoJasper.java:57)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Unknown Source)

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester

Where did you put the jar file that contains this class?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64620
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic