Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
saurabh joshi
Trying to call Jasper iReport through portlet & getting error
November 27, 2007 10:03 PM
Answer

saurabh joshi

Rank: Junior Member

Posts: 51

Join Date: August 6, 2007

Recent Posts

Hi,

I have written the following code which is linked to a button in my portlet.
  1
  2package com.ext.portlet.drpdwn.action;
  3
  4import com.liferay.portal.struts.PortletAction;
  5import com.liferay.portal.util.Constants;
  6import javax.portlet.WindowState;
  7import javax.servlet.jsp.PageContext;
  8
  9import javax.portlet.ActionRequest;
 10import javax.portlet.ActionResponse;
 11import javax.portlet.PortletConfig;
 12import javax.portlet.RenderRequest;
 13import javax.portlet.RenderResponse;
 14import org.apache.struts.action.ActionForm;
 15import org.apache.struts.action.ActionForward;
 16import org.apache.struts.action.ActionMapping;
 17
 18import java.io.IOException;
 19import java.io.PrintWriter;
 20import java.io.StringWriter;
 21import java.util.HashMap;
 22import java.util.Map;
 23import java.sql.*;
 24import javax.portlet.PortletException;
 25import net.sf.jasperreports.engine.*;
 26import net.sf.jasperreports.engine.design.JasperDesign;
 27import net.sf.jasperreports.engine.xml.JRXmlLoader;
 28import net.sf.jasperreports.engine.export.*;
 29
 30public class QualityReportAction extends PortletAction
 31{
 32    public void processAction(ActionMapping mapping, ActionForm form,PortletConfig config,ActionRequest req, ActionResponse res)
 33
 34throws Exception
 35    {
 36
 37        String typeofreport_val = req.getParameter("types_of_reports").trim();
 38       
 39        System.out.println("Report Name is:" +typeofreport_val);
 40        JasperReport jasperReport;
 41        JasperPrint jasperPrint;
 42        JasperDesign jasperDesign;
 43        Connection connection = null;
 44
 45        if ( null == typeofreport_val || "".equals("typeofreport_val"))
 46        {
 47            setForward(req,"portlet.ext.drpdwn.error");
 48        }
 49        else
 50        {
 51            try
 52            {
 53                Class.forName("org.postgresql.Driver");
 54
 55                String url = "jdbc:postgresql://10.10.33.39:5432/globus_db?user=postgres&password=marines@123";
 56               
 57                connection = DriverManager.getConnection(url);
 58                // load JasperDesign from XML and compile it into JasperReport
 59                jasperDesign = JRXmlLoader.load("C:/testRep/CCQR.jrxml");
 60                jasperReport = JasperCompileManager.compileReport(jasperDesign);
 61            
 62
 63                // fill JasperPrint using fillReport() method
 64                jasperPrint = JasperFillManager.fillReport(jasperReport,null,connection);
 65
 66                JasperExportManager.exportReportToPdfFile(jasperPrint,"C:/testRep/ccqr.pdf");
 67            }   
 68                   
 69            catch (SQLException ex)
 70            {
 71                setForward(req,"portlet.ext.drpdwn.error");
 72                System.out.println("-------------------------------------------");
 73                while (ex != null)
 74                {
 75                    ex.printStackTrace();
 76                    ex = ex.getNextException();
 77                }
 78                System.out.println("-------------------------------------------");
 79            }
 80            catch(Exception e)
 81            {
 82                System.out.println("-------------------------------------------");
 83                System.out.println("Exception is --> "+e);
 84                System.out.println("-------------------------------------------");
 85            }
 86            setForward(req,"portlet.ext.drpdwn.success");               
 87        }
 88    }
 89    public ActionForward render(ActionMapping mapping,ActionForm form,PortletConfig config, RenderRequest req,RenderResponse res) throws Exception
 90    {
 91        if (getForward(req) != null && !getForward(req).equals(""))
 92        {
 93            return mapping.findForward(getForward(req));
 94        }
 95        else
 96        {
 97            return
 98            mapping.findForward("portlet.ext.drpdwn.view");
 99        }
100    }
101}


When I try to run this code I get the following error:

 1
 2exception  javax.servlet.ServletException: Servlet execution threw an exception
 3    com.liferay.filters.secure.SecureFilter.doFilter(SecureFilter.java:144)
 4    com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:136)
 5    com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:126)
 6    javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
 7    com.liferay.filters.strip.StripFilter.doFilter(StripFilter.java:95)
 8    com.liferay.filters.secure.SecureFilter.doFilter(SecureFilter.java:144)
 9    com.liferay.filters.compression.CompressionFilter.doFilter(CompressionFilter.java:116)
10    com.liferay.filters.doubleclick.DoubleClickFilter.doFilter(DoubleClickFilter.java:138)
11    com.liferay.portal.servlet.filters.layoutcache.LayoutCacheFilter.doFilter(LayoutCacheFilter.java:170)
12    com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.doFilter(AutoLoginFilter.java:106)
13    com.liferay.portal.servlet.filters.virtualhost.VirtualHostFilter.doFilter(VirtualHostFilter.java:136) 
14root cause  java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/xml/JRXmlLoader    com.ext.portlet.drpdwn.action.QualityReportAction.processAction(QualityReportAction.java:59)


I have the following necessary files in my class path:
 1
 2itext-1.3.1.jar
 3iReport.jar
 4commons-logging-1.0.2.jar
 5commons-javaflow-20060411.jar
 6commons-digester-1.7.jar
 7commons-collections-2.1.jar
 8commons-beanutils-1.7.jar
 9jasperreports-2.0.2.jar
10jdt-compiler-3.1.1.jar
11log4j-1.2.15.jar
12xercesImpl.jar   

Please suggest me where I am going wrong.

Thanks & Regards
Saurabh.
Roman Hoyenko
RE: Trying to call Jasper iReport through portlet & getting error
November 28, 2007 8:40 AM
Answer

Roman Hoyenko

Rank: Liferay Master

Posts: 868

Join Date: October 8, 2007

Recent Posts

It doesn't find
java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/xml/JRXmlLoader

What do you mean "in my classpath" - where exactly are those classes and are they available to your app?
saurabh joshi
RE: Trying to call Jasper iReport through portlet & getting error
November 29, 2007 9:54 PM
Answer

saurabh joshi

Rank: Junior Member

Posts: 51

Join Date: August 6, 2007

Recent Posts

Hi Roman,

I apologize for replying so late.
Actually you almost gussed it right, although I mentioned the .jar files in the CLASSPATH but one of the .jar file was missing in my ..WEB-INF/lib dir.

So the issue is solved now.
Thanks for your time.
Saurabh.