Java Xml file to Jasper converter : How to convert Xml file into Jasper in Java using jasper-compiler, jasper-runtime and jasper_bundle||Source code example included.

xml to jasper javaFor 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


jasper to xml conversion java

2 Responses to Java Xml file to Jasper converter : How to convert Xml file into Jasper in Java using jasper-compiler, jasper-runtime and jasper_bundle||Source code example included.

  1. Pallav says:

    Can you send me the Java code and xmlfile to be converted in attachment.
    I will be very thankful to u

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s