markusin77 Posted April 11, 2016 Share Posted April 11, 2016 Hello,I am trying to run the jasperreports libraries inside the servlet container (Jetty). The steps I implemented is first compiling the reports and second filling the reports with data from a JDBC connection.The first step is elaborated without exceptions, where calling JasperCompileManager, but in the second step a got a NoClassDefFoundError: net/sf/jasperreports/engine/JasperFillManager.I ensured the jar file is in the classpath (I am using jetty:run maven plugin).my code here: public void createReportFile(PostgresConnector destConnector, Integer inspectionId) { try { File jrxmlFile = new File(Thread.currentThread().getContextClassLoader().getResource("jasper/jrxml/main.jrxml").toURI()); File jasperFile = new File(Thread.currentThread().getContextClassLoader().getResource("jasper/jrxml/main.jasper").toURI()); // Compiling jasper report logger.info("Compiling report file " + jasperFile.getAbsolutePath()); JasperCompileManager.compileReportToFile(jrxmlFile.getAbsolutePath(), jasperFile.getAbsolutePath()); // Create arguments Map<String,Object> params = new HashMap<String,Object>(); params.put("id_inspection", inspectionId); params.put("userLocale", "it_IT"); params.put("use_signature", Boolean.FALSE); params.put("headquarter", "Bolzano, il"); // Filling data into jasper file logger.info("Filling data into report file " + jasperFile.getAbsolutePath()); JasperPrint jprint = (JasperPrint) JasperFillManager.fillReport(jasperFile.getAbsolutePath(), params, destConnector.getConnection()); // Export pdf file String reportPath = config.getProperty("server.reportDirectory"); Inspection inspection = model.getInspection(inspectionId); String pdfFileName = reportPath + inspection.getReportFilename(); logger.info("Creating pdf report file " + pdfFileName); JasperExportManager.exportReportToPdfFile(jprint, pdfFileName); } catch (Exception e) { logger.warn("Error when generating jasper report", e); } }[/code]and this is the stack trace: [WARNING] Error for /inspector/configjava.lang.NoClassDefFoundError: net/sf/jasperreports/engine/JasperFillManager at com.hydrosafety.inspector.manager.controller.Controller.createReportFile(Controller.java:1329) at com.hydrosafety.inspector.manager.servlets.ConfigServlet.processGenerateReportRequest(ConfigServlet.java:225) at com.hydrosafety.inspector.manager.servlets.ConfigServlet.processRequest(ConfigServlet.java:166) at com.hydrosafety.inspector.manager.servlets.ConfigServlet.doGet(ConfigServlet.java:112) at javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:835) at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:583) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548) at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226) at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1158) at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511) at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185) at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1090) at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213) at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109) at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:119) at org.eclipse.jetty.server.Server.handle(Server.java:517) at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308) at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:242) at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273) at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95) at org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:75) at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:213) at org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:147) at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654) at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572) at java.lang.Thread.run(Thread.java:745)Caused by: java.lang.ClassNotFoundException: net.sf.jasperreports.engine.JasperFillManager at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239) at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:487) at org.eclipse.jetty.webapp.WebAppClassLoader.loadClass(WebAppClassLoader.java:428) ... 30 more[/code]thanks for any suggestionMarkus Link to comment Share on other sites More sharing options...
hozawa Posted April 12, 2016 Share Posted April 12, 2016 Nope, jasperreports.jar is not being recognized in the classpath - that's why you're getting the error.That beside, it's better to precompile jrxml to jasper file and use that - it's much faster without the compile. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now