0

I'm trying to call jasper report from Oracle ADF. I've include below jar files into the class path

apache-ant-1.7.1.jar
groovy-all-2.0.1.jar
itext-2.1.7.js2.jar
jasperreports-6.1.0.jar
jasperreports-fonts-6.1.0.jar
jasperreports-javaflow-6.1.0.jar
jcommon-1.0.15.jar
jfreechart-1.0.12.jar
poi-3.10.1.jar

Below is the code I'm using to call the report

HttpServletResponse response = getResponse();
             ServletOutputStream out = response.getOutputStream();
             response.setHeader("Cache-Control", "max-age=0");
             response.setContentType("application/pdf");
             ServletContext context = getContext();

            InputStream fs = new FileInputStream(new File(context.getRealPath("/reports/usman.jasper")));

             JasperReport template = (JasperReport) JRLoader.loadObject(fs);
             template.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);

        JasperPrint print;
        print = JasperFillManager.fillReport(template, null);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
             JasperExportManager.exportReportToPdfStream(print, baos);
             out.write(baos.toByteArray());
             out.flush();
             out.close();
        FacesContext.getCurrentInstance().responseComplete();

When i run the code i get below error:

Caused by: java.lang.NoClassDefFoundError: net/sf/jasperreports/engine/util/JRLoader
    at Test.b2_action(Test.java:70)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at org.apache.myfaces.trinidad.component.MethodExpressionMethodBinding.invoke(MethodExpressionMethodBinding.java:46)
    ... 74 more

Please help me resolve this error. am i missing a jar ?

divibisan
  • 11,659
  • 11
  • 40
  • 58
Usman Riaz
  • 2,920
  • 10
  • 43
  • 66
  • have you imported `JRLoader`? – Lino Jul 27 '17 at 07:07
  • import net.sf.jasperreports.engine.util.JRLoader; Yes – Usman Riaz Jul 27 '17 at 07:08
  • 1
    maybe have a look at this: https://stackoverflow.com/questions/34413/why-am-i-getting-a-noclassdeffounderror-in-java. are you sure the class is available at runtime? – Lino Jul 27 '17 at 07:10
  • How to be sure of that ? – Usman Riaz Jul 27 '17 at 07:11
  • 1
    are you using a build tool or something like this? if not have you compiled all the files needed to execute your code? – Lino Jul 27 '17 at 07:12
  • jasperreports-6.1.0.jar has that class...there must be some conflict among the jars – Akshay Jul 27 '17 at 07:14
  • 1
    Basic test press ctrl+shift+T and type the missing classname. you should be able to see the class in some of the above jar, if the Jar is in classpath. If that is there, then I would suggest to rebuild the complete app (refresh dependencies like in Gradle) and retry. If still not working than follow this link http://javareferencegv.blogspot.in/2013/10/debugging-javalangnoclassdeffounderror.html – sakura Jul 27 '17 at 07:16
  • @Lino i'm using jdeveloper 12c. – Usman Riaz Jul 27 '17 at 07:19
  • 3
    @UsmanRiaz Try to remove `jasperreports-javaflow-6.1.0.jar` from cp. You don't need to have both *JR* jars (`jasperreports-javaflow-6.1.0.jar` & `jasperreports-6.1.0.jar`) at cp – Alex K Jul 27 '17 at 07:31

1 Answers1

0

Just restarted the JDeveloper and build the project and problem was solved. class files were missing from the class path.

Usman Riaz
  • 2,920
  • 10
  • 43
  • 66