For the reporting purpose sometimes we may need to convert xml file into jasper.
Here I have tried to show you the conversion procedure of xml file to jasper file using Java Programming Language.
To do this you need the following jar (drivers actually) files
1. jasper-compiler.jar
2. jasper-runtime.jar
3. jasper_bundle.jar
Below, I have attached the Java Source Code of XML to JASPER Converter, Code to compile and run the source code. Also I have included an Image to show you the whole procedure.
Java Code Example : XML to JASPER converter
import dori.jasper.engine.JasperCompileManager;
public class XmlToJasperConverter {
JasperCompileManager jasperCompileManager;
private void make(String sourceFileName,String outPutFileName)
{
try{
jasperCompileManager=new JasperCompileManager();
jasperCompileManager.compileReportToFile(sourceFileName, outPutFileName);
System.out.println(“\n\nfile converted . . . “);
}
catch(Exception ex)
{
System.out.println(ex.getMessage());
}
}
public static void main(String[] args) {
XmlToJasperConverter converter=new XmlToJasperConverter();
converter.make(“C:\\myworkspace\\xml-to-jasper\\Accessory_Purchase.xml”,”C:\\myworkspace\\xml-to-jasper\\Accessory_Purchase.jasper”);
}
}
How to Run the Code (I have attached the Image below):
Note : I have Compiled and Run the Source Code in my pc at “C:\myworkspace\xml-to-jasper\” for my convenience
You can use your own folder to do this.
To compile the Compiler Source Code
javac -g -classpath ";.;C:\myworkspace\xml-to-jasper\jasper_bundle.jar;C:\myworkspace\xml-to-jasper\jasper-runtime.jar;C:\myworkspace\xml-to-jasper\jasper-compiler.jar;" XmlToJasperConverter.java
To Run the Converter Source Code
java -classpath ";.;C:\myworkspace\xml-to-jasper\jasper_bundle.jar;C:\myworkspace\xml-to-jasper\jasper-runtime.jar;C:\myworkspace\xml-to-jasper\jasper-compiler.jar;" XmlToJasperConverter
Image
Can you send me the Java code and xmlfile to be converted in attachment.
I will be very thankful to u
LikeLike
Hi Pallav…Actually this problem i faced and blogged it several months ago…… not sure that files i have or not….need to check..
LikeLike