Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

decompile jasper

  Asked By: Rainhard    Date: Sep 11    Category: Java    Views: 2409
  

I must decompile my jasper files to the original xml files (.jrxml)
and I could not do it through iReport, does anybody have a solution on this.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Muntasir Bashara     Answered On: Sep 11

I found solution  by myself, of course!
here is my code (converting jasper  to jrxml)
enjoy now

import java.io.File;

import net.sf.jasperreports.engine.JRException;

import net.sf.jasperreports.engine.JasperReport;
import net.sf.jasperreports.engine.design.JasperDesign;

import net.sf.jasperreports.engine.util.JRLoader;

import net.sf.jasperreports.engine.xml.JRXmlWriter;

public class JasperToJRXML {

public static String sourcePath,
destinationPath,
xml;


public static JasperDesign jd = new JasperDesign();

public static void main(String[] args) throws JRException {


// Paths
File dir = new File("C:\\jaspers\\");


if (dir.isDirectory()) {
File[] jaspers = dir.listFiles();

for (int i = 0; i < jaspers.length; i++) {
String outputPath = "c:\\jrxml\\";
String ext = getFileExtenstion(jaspers[i]);

if (ext.equalsIgnoreCase(".jasper")) {

JasperReport report =
(JasperReport)JRLoader.loadObject(jaspers[i]);
outputPath += getFileName(jaspers[i]) + ".jrxml";
JRXmlWriter.writeReport(report, outputPath, "UTF-8");

}
System.out.println(ext);
}
}

}

private static String getFileExtenstion(File file) {
String fileName = file.getName();
int i = fileName.indexOf(".");
return fileName.substring(i, fileName.length());
}

private static String getFileName(File file) {
String fileName = file.getName();
int i = fileName.indexOf(".");
return fileName.substring(0, i);
}
}

 
Didn't find what you were looking for? Find more on decompile jasper Or get search suggestion and latest updates.




Tagged: