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.FileNotF
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
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>
To help future users:
I see these problems
.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?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");
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