3

I am trying to create Jasper Report in Liferay portlet but I am getting below error:

   Caused by: net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException:    src\com\ztscorp\lms\reports\HibernateQueryDemoReport.jasper (The system cannot find the path specified)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:176)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:143)
        at com.ztscorp.lms.portlet.SurveyReportController.processSearchSurvey(SurveyReportController.java:86)
        ... 175 more
Caused by: java.io.FileNotFoundException: src\com\ztscorp\lms\reports\HibernateQueryDemoReport.jasper (The system cannot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:171)
        ... 178 more
13:08:01,916 ERROR [[SurveyReportAdministration]] Servlet.service() for servlet SurveyReportAdministration threw exception
java.io.FileNotFoundException: src\com\ztscorp\lms\reports\HibernateQueryDemoReport.jasper (The system cannot find the path specified)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:171)
        at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:156)
        at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:143)
        at com.ztscorp.lms.portlet.SurveyReportController.processSearchSurvey(SurveyReportController.java:86)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at javax.portlet.GenericPortlet.processAction(GenericPortlet.java:169)
        at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:70)
        at com.liferay.portal.kernel.portlet.PortletFilterUtil.doFilter(PortletFilterUtil.java:48)
        at com.liferay.portal.kernel.servlet.PortletServlet.service(PortletServlet.java:92)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter  (ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.ztscorp.lms.utils.AuthenticateFilter.doFilter(AuthenticateFilter.java:99)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
        at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:543)
        at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:480)
        at com.liferay.portlet.InvokerPortletImpl.invoke(InvokerPortletImpl.java:638)
        at com.liferay.portlet.InvokerPortletImpl.invokeAction(InvokerPortletImpl.java:687)
        at com.liferay.portlet.InvokerPortletImpl.processAction(InvokerPortletImpl.java:360)
        at com.liferay.portal.action.LayoutAction.processPortletRequest(LayoutAction.java:784)
        at com.liferay.portal.action.LayoutAction.processLayout(LayoutAction.java:582)
        at com.liferay.portal.action.LayoutAction.execute(LayoutAction.java:232)
        at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
        at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
        at com.liferay.portal.struts.PortalRequestProcessor.process(PortalRequestProcessor.java:153)
        at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
        at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
        at com.liferay.portal.servlet.MainServlet.callParentService(MainServlet.java:508)
        at com.liferay.portal.servlet.MainServlet.service(MainServlet.java:485)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:309)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:121)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.autologin.AutoLoginFilter.processFilter(AutoLoginFilter.java:254)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
        at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:444)
        at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
        at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
        at com.liferay.portal.servlet.FriendlyURLServlet.service(FriendlyURLServlet.java:134)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.strip.StripFilter.processFilter(StripFilter.java:261)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:126)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.gzip.GZipFilter.processFilter(GZipFilter.java:110)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.secure.SecureFilter.processFilter(SecureFilter.java:182)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at com.liferay.portal.kernel.servlet.BaseFilter.processFilter(BaseFilter.java:196)
        at com.liferay.portal.servlet.filters.i18n.I18nFilter.processFilter(I18nFilter.java:222)
        at com.liferay.portal.kernel.servlet.BaseFilter.doFilter(BaseFilter.java:123)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)

Here is my code:

Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/lms?user=root&password=admin");

JasperReport report = JasperCompileManager.compileReport("src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jasper");
JasperPrint print = JasperFillManager.fillReport(report, new HashMap(), connection);
JasperExportManager.exportReportToPdfFile(print, "reports/myjasperfile.pdf");

Please help me.

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
saloni
  • 173
  • 2
  • 3
  • 16
  • 1
    You can read the javadoc: http://jasperreports.sourceforge.net/api/net/sf/jasperreports/engine/JasperCompileManager.html#compileReport%28java.lang.String%29 – Alex K Jan 06 '12 at 13:52

4 Answers4

1

To help future users:

I see these problems

  1. OP is trying to compile .jasper, these .jasper files are already compiled the command JasperCompileManager.compileReport should be used to compile .jrxml to .jasper. For more information of jasper report file types see What is the difference between JasperReport formats?
  2. If you have you .jasper inside of your package/distribution (src), the correct way to load the report would be using a class loader (hence src will change to bin).

    InputStream jasperStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("com/ztscorp/lms/reports/HibernateQueryDemoReport.jasper");
    JasperReport report = (JasperReport) JRLoader.loadObject(jasperStream);
    

    If it outside of the distribution you can simple use File with the relative or absolute path

    JasperReport report = (JasperReport) JRLoader.loadObject(new File("jasperFolder/HibernateQueryDemoReport.jasper");
    
Community
  • 1
  • 1
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
1

OK.Guys this worked for me

  ***con=DBConnection.getConnection();
  JasperPrint  jp = JasperManager.fillReport(<reportname>.jasper",null,con);
        JasperViewer.viewReport(jp, false);***

After this copy or cut the jasperfile eg.(your_reportname.jasper and your_reportname.jrxml) and go to the File directory of your project(easy to find in netbeans) and paste them in the build.xml folder of the project .Making sure you have imported the necesasry class jars and run.. im using the jasperreport 3.7.4 plugin for netbeans in my netbeans ide

jaYjaY
  • 21
  • 7
0

In my case I had an image url parameter and had to explicitly set the attribute isForPropmting to false like this:

<parameter name="LOGO_URL" class="java.lang.String" isForPrompting="false">
        <defaultValueExpression><![CDATA[]]></defaultValueExpression>
    </parameter>
Christian Vielma
  • 15,263
  • 12
  • 53
  • 60
0

I think your .jasper file is not in your context path of application (Atleast the application is not finding it).

Are you sure the /report folder is in build path?? If not, add it to build path.

Otherwise try to use something like this JasperReport report = JasperCompileManager.compileReport("classpath:src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jasper");

try this,

change

JasperReport report = JasperCompileManager.compileReport("src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jrxml");

to

JasperReport report = JasperCompileManager.compileReport(new File("").getAbsolutePath()+"src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jrxml");

Hope it helps,

-Anuj

Anuj Patel
  • 17,261
  • 3
  • 30
  • 57
  • what exacatly i have to write in build.xml file because in build.xml file I wrote code for compilation of src.dir. – saloni Jan 06 '12 at 13:38
  • Eclipse 3.4 and jboss as a server – saloni Jan 06 '12 at 13:46
  • Now I am writing JasperReport report = JasperCompileManager.compileReport("src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jrxml");But still getting same error – saloni Jan 06 '12 at 14:03
  • I made the changes as u suggested but same problem occuring so I think is there any compilation error, I mean is there possibility that folder is compiling properly. – saloni Jan 06 '12 at 14:40
  • give me 15 min i ll try my code in netbeans and will reply. plus if u can send over the code it would be best..!!! – Anuj Patel Jan 06 '12 at 14:43
  • now just try this in your original code change 1 to 2. 1) JasperReport report = JasperCompileManager.compileReport("src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jrxml"); 2)JasperReport report = JasperCompileManager.compileReport(new File("").getAbsolutePath()+"src/com/ztscorp/lms/reports/HibernateQueryDemoReport.jrxml"); notice change in #2, gets working dir of application.! PS: this is a work around and not good programming practice. hope this time it works.. – Anuj Patel Jan 06 '12 at 15:12
  • After given absoult path it is giving this error at java.lang.Class.forName(Class.java:247) at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForRealName(JRClassLoader.java:157) at net.sf.jasperreports.engine.util.JRClassLoader.loadClassForName(JRClassLoader.java:115) at net.sf.jasperreports.engine.util.JRSingletonCache.createInstance(JRSingletonCache.java:85) at net.sf.jasperreports.engine.util.JRSingletonCache.getCachedInstance(JRSingletonCache.java:74) at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.createParser(JRXmlDigesterFactory.java:1341) – saloni Jan 09 '12 at 12:17
  • do you have all required jar (jasper is dependent on some other libs) in classpath?? i doubt this is due to common.*.jar missing. PS: this is speculation based on error above, if u can please post the code thanks with line # or full code. Thanks – Anuj Patel Jan 09 '12 at 13:06
  • @Anuj sorry I couldn't post the full error as here I am getting error as Your post does not have much context to explain the code sections; please explain your scenario more clearly – saloni Jan 09 '12 at 13:37
  • ohk, i am giving u whole code just give me some time, i m stuck on my own project a lil but.. just abt half n hour..!! – Anuj Patel Jan 09 '12 at 14:36
  • http://stackoverflow.com/questions/3718201/how-to-add-resources-to-classpath check this one out, googled lot as i dont knw anything abt ant and finally found this.. may be help.. + my code in netbeans is ready where i can generate PDF do let me knw if u need it..!!! Thanks. – Anuj Patel Jan 09 '12 at 15:09
  • http://stackoverflow.com/questions/8815094/null-pointer-exception-while-creating-jasper-report .. please find this link i posted new question – saloni Jan 11 '12 at 06:45