Hi i have problem in jasper reports.. im executing jrxml through my java class shown below
String jrxmlPath = context.getRealPath("//IREPORT_JRXML//" + reportPath);
System.out.println("in BTO report Selected " +jasperReport); ---->(1)
JasperReport jasperReport = JasperCompileManager.compileReport(jrxmlPath);
System.out.println("in BTO report compiled " +jasperReport); ----->(2)
"//IREPORT_JRXML// is the path where i put jrxml file. i executed my application control is executing up to ---->(1) line but it doesnt executing belo statements,here the problem is at lest i doesnt showing any error on console.
im using IReport 4.0.2,tomcat 7,jdk 1.7 , i added jasperreport-3.7.4.jar file in lib folder.
is there any issue about version problems? IReport 4.0.2,tomcat 7,jdk 1.7 and web dynamic Module 3.0
i tried to find out the problem unfortunately i missed some library... but i dint remember which library it is ... jasper compiler doesnt executing report design elements,report without design elements is executing , can anybody tell me wat library / jar i need to add for executing report design elements.....
Please try the following code
`ServletContext context = getServletContext();
String reportPath = context
.getRealPath("/WEB-INF/reports/filname.jasper");
JasperReport jasperReport =
JasperCompileManager.compileReport(reportPath);`
Related
I followed this code example, when i made some report with sub report using iReport v2.0.4
Now i want to run by Java this reports. My code is:
String rs="E:\\Myproject\\NetBeansProjects\\Inventory_control_system_for_hotel\\
Mainreportname.jrxml";
JasperReport jasperMasterReport = JasperCompileManager.compileReport(rs);
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("para_custId", "66778999");
JasperPrint jasperPrint=JasperFillManager.fillReport(jasperMasterReport, parameters, JDBC41.con());
JasperViewer.viewReport(jasperPrint, false);
Give following error
net.sf.jasperreports.engine.JRException: Could not load object from location\Invoice_ireport_subreport2.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObjectFromLocation(JRLoader.java:266)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluateSubreport(JRFillSubreport.java:308)
at net.sf.jasperreports.engine.fill.JRFillSubreport.evaluate(JRFillSubreport.java:257)
at net.sf.jasperreports.engine.fill.JRFillElementContainer.evaluate(JRFillElementContainer.java:275)
at net.sf.jasperreports.engine.fill.JRFillBand.evaluate(JRFillBand.java:426)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillColumnBand(JRVerticalFiller.java:1380)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillDetail(JRVerticalFiller.java:692)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportStart(JRVerticalFiller.java:255)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:113)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:891)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:795)
at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:402)
at inventory_control_system_for_hotel.newquery.main(newquery.java:77)
Now I am change my Ireport version 5.5 Some thing like this error
`java.lang.NullPointerException
at net.sf.jasperreports.engine.JRPropertiesMap.readObject(JRPropertiesMap.java:185)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)`
Save my report Path=E:\Myproject\NetBeansProjects\Inventory_control_system_for_hotel\Mainreportname.jrxml
Sub repoth=E:\Myproject\NetBeansProjects\Inventory_control_system_for_hotel\Subreportname.jrxml
Like this
When you link the report and subreport in ireport, you have to set the property "subreport expresion" that is a path relative to your classpath where your subreport is.
Subreport expresion = "reports/Invoice_ireport_subreport2.jasper.jasper"
and you have in your project something like:
src/main/resources/reports/Invoice_ireport_subreport2.jasper.jasper
I am trying to build a Dynamic web project where user can practice Java code.
I got success on writing the code written by user in a .java file, compile the code & get error messages using Java Compile API.
Now, I need to run JUnit 1.4 Compatible test on that code.
I researched for it, and found something like parameterized junit testing. But my view on how should it be done isn't still clear.
UPDATE
This (http://codingbat.com/prob/p171896) is the exact thing what I'm trying to implement.
I solved this problem with the following steps:
Compile the JUnit TestClass and the ClassToTest
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
int compilerResult = compiler.run(null, null, null,"/path/to/TestClass.java", "/path/to/ClassToTest.java");
System.out.println("Compiler result code: " + compilerResult);
Load the compiled classes into the classloader
File dir = new File("/path/to/class/files/");
URL url = dir.toURI().toURL();
URL[] urls = {url};
ClassLoader classLoader = new URLClassLoader(urls);
Run the tests (make sure that you add junit as a dependency of your project)
Class<?> junitTest = Class.forName("TestClass", true, classLoader);
Result result = junit.run(junitTest);
Edit: If you're not needing the JUnit tests to be dynamic you can skip the compilation of those tests and add them here: junit.run(JunitTest.class)
I'm using grails version 2.4.0 and JasperReports plugin: 1.9.0 (also tried version jasper-1.10.0-SNAPSHOT) but when I export to pdf I got errors.
When I first start project, I run export report and got this message
org.apache.commons.collections.map.ReferenceMap
After that when I try again and it shows this error.
Could not initialize class net.sf.jasperreports.engine.xml.JRXmlDigesterFactory
It seems to be in competitive with version 2.4.0 because it works on 2.2.4
Here my code
In controller
def results = new ArrayList()
def reportFolder = "${grailsApplication.parentContext.getResource('reports').file.absolutePath}"
def sep = System.getProperty('file.separator')
def app = Applicant.get(2)
results.add(
first: app.firstName,
middle: app?.middleInitial,
last: app.lastName,
ssn: app.ssn,
workPhone: app.workPhone,
homePhone: app.homePhone
)
reportService.exportPDFReport("${reportFolder}${sep}aaa.jrxml", results, params, response)
In service (note that service named: reportService)
def exportPDFReport(String reportPath, results, params, response) {
def temp_file = File.createTempFile("jasperReport", ".pdf")
def jrDataSource = new JRMapCollectionDataSource(results)
JasperReport jReport = JasperCompileManager.compileReport(reportPath)
JasperPrint print = JasperFillManager.fillReport(jReport, params, jrDataSource)
JasperExportManager.exportReportToPdfFile(print, temp_file.absolutePath)
response.setContentType("application/force-download")
response.setHeader("Content-Transfer-Encoding", "binary")
response.setHeader("Content-disposition", "attachment; filename=${jReport.name}.pdf")
response.outputStream << temp_file.newInputStream()
temp_file.deleteOnExit()
}
Any ideas?
In version 2.4 or later. you can't combine jasper plugin because it is missing libraries from third part.
It is very easy to resolve that problem. You only need copy these jars to your /lid
org.apache.commons.collections.jar
commons-beanutils-1.9.2.jar
Sure 100% it work :-)
In version 2.4 the Holder static classes where removed. For plugins that still use these classes they cause errors. I would also try version 2.4.2 instead for grins. Could you also edit and give us a complete stack trace to help in debugging.
I'm using JasperReports 4.7.1 plugin for NetBeans 7.2 to generate report from mysql database
and while I run the application from the ide there is no problem found accept this warnings:
log4j:WARN No appenders could be found for logger (net.sf.jasperreports.engine.xml.JRXmlDigesterFactory).
log4j:WARN Please initialize the log4j system properly.
But the report generated and viewed correctly.
The problem is while I clean and build the application then rung it from the jar file the report does not generated and does not give me any exceptions just no reports viewed and every thing else is normal?
This is the function I use for viewing the report in JasperViewer:
public void printInvoice(int invid) throws IOException {
try {
String sql = "SELECT\n" +
" ordersdetails.`ITEMNAME` AS ordersdetails_ITEMNAME,\n" +
" ordersdetails.`AMOUNT` AS ordersdetails_AMOUNT,\n" +
" ordersdetails.`PRICE` AS ordersdetails_PRICE,\n" +
" invoices.`INVOICEID` AS invoices_INVOICEID,\n" +
" invoices.`CUSTOMER` AS invoices_CUSTOMER,\n" +
" invoices.`THEDATE` AS invoices_THEDATE,\n" +
" invoices.`COST` AS invoices_COST\n" +
"FROM\n" +
" `invoices` invoices RIGHT OUTER JOIN `ordersdetails` ordersdetails ON invoices.`INVOICEID` = ordersdetails.`INVOICE` where invoices.invoiceid=" + invid;
InputStream in = this.getClass().getResourceAsStream("/reports/invoice.jrxml");
JasperDesign jd = JRXmlLoader.load(in);
JRDesignQuery q = new JRDesignQuery();
q.setText(sql);
jd.setQuery(q);
JasperReport jasp_rep = JasperCompileManager.compileReport(jd);
JasperPrint jasp_print = JasperFillManager.fillReport(jasp_rep, null, mc.getConnection());
JasperViewer.viewReport(jasp_print, false);
} catch (JRException e) {
JOptionPane.showMessageDialog(null, e.getMessage());
System.out.println(e);
}
}
Propably load the report from the wrong location, try relative path:
InputStream in = this.getClass().getResourceAsStream("reports/invoice.jrxml");
That means there is the invoice.jrxml in the report folder and that folder is at same level as the class (this.getClass()) that invokes getResourceAsStream.
Additionaly you can get around the warning with
org.apache.log4j.BasicConfigurator.configure();
at beginning of your program.
Do not run the jar file directly. Instead, run it from the command line using java -jar myjar.jar as #PeterMmm has said in the comments above and you will see the errors listed. Try to find the error from that. I think the error is probably a NoClassDefFoundError and it is due to a wrong version of a library file. If that is the reason, download a correct version of the library jar file which contain the missing class definitions and add it to the project library and build the project.
I created a Java method and I want to call it from a report, like this:
package javafunct;
public class Main {
public String getTes(){
return "it work";
}
}
I want to show that result in my JR report, so I put that on a textField with expression:
new javafunct.Main().getTes()
I compiled that, and then I set that jar file to the iReport classpath and my PHP code.
When I run it from iReport, it works, but when I run from PHP to open this report, it does not work. The error is:
Error evaluating expression :
Source text : new javafunct.Main().getTes()
ok,i solved my problem.. i must put javaFunct.jar to folder javaBridge/WEB-INF/lib in my tomcat and then restart tomcat.