Jump to content
JasperReports Library 7.0 is now available ×

.jasper to .jrxml (uncompile/decompile)


redwine

Recommended Posts

hello!

 

i need all the help i can get on this.

thanks to everyone who will be able to post a solution. :)

 

 

REQUIRED:

to be able to convert the .jasper file (File1.jasper) to a .jrxml file (File2.jrxml).

meaning, i need the .xml code so that we (developers) could make changes to the old form/report.

currently, we are in the dark on how to reverse the normal process (from .jrxml to .jasper).

 

 

SITUATION:

i have a .jasper file that, unfortunately, does not have the original .jrxml file anymore.

i have written the following java application that i hoped would convert a .jasper file to a .jrxml file.

 

----------

Code:

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.design.JasperDesign;
import net.sf.jasperreports.engine.xml.JRXmlLoader;
import net.sf.jasperreports.engine.xml.JRXmlWriter;

class JasperToXml
{
public static String sourcePath,
destinationPath,
xml;

public static JasperDesign jd = new JasperDesign();

public static void main(String [] args) {

// Paths
sourcePath = "C:\Documents and Settings\user\My Documents\workspaces\jasper\File1.jasper";
outputPath = "C:\Documents and Settings\user\My Documents\workspaces\jrxml\File2.jrxml";

try
{
// for converting a JasperReport object (compiled .jasper file) to a JasperDesign object
jd = JRXmlLoader.load(sourcePath);
// is this the right way to do it???
}
catch(JRException e)
{
e.printStackTrace();
}
JRXmlWriter.writeReport(jd, outputPath); //
}
}

----------

 

it does not have any errors in the code according to eclipse but unfortunately it does not work when i try to run it.

... i think i did an oversimplified application which produces the following error message:

 

----------

net.sf.jasperreports.engine.JRException: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:247)

at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:226)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:214)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:168)

at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:152)

at JasperToXml.main(JasperToJrxml.java:28)

Caused by: com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 1 of 1-byte UTF-8 sequence.

at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:713)

at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.read(UTF8Reader.java:586)

at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.load(XMLEntityScanner.java:1740)

at com.sun.org.apache.xerces.internal.impl.XMLEntityScanner.skipString(XMLEntityScanner.java:1437)

at com.sun.org.apache.xerces.internal.impl.XMLVersionDetector.determineDocVersion(XMLVersionDetector.java:191)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:798)

at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:764)

at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:148)

at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1242)

----------

 

i'm thinking it has to have a lot more put into it than it currently has... i just don't see what else it needs.

note that i have already added the following jars to my eclipse classpath after successive error messages prompted me to add them:

commons-collections-3.2

commons-digester-1.8

commons-logging-1.1

 

 

REQUEST:

a good discussion on how to go about this.

maybe a couple of detailed explanations to make things clearer.

as always a working java app would be the best :)

 

Thanks in advance for your help!

 

 

edwin

Post edited by: redwine, at: 2007/05/29 22:18

Link to comment
Share on other sites

  • Replies 9
  • Created
  • Last Reply

Top Posters In This Topic

*.jasper files are (usually) serialized net.sf.jasperreports.engine.JasperReport objects.

 

Therefore you need to do

Code:

sourcePath = "..File1.jasper";
outputPath = "...File2.jrxml";
JasperReport report = (JasperReport) JRLoader.loadObject(sourcePath);
JRXmlWriter.writeReport(report, outputPath, "UTF-8"«»);

 

HTH,

Lucian

Link to comment
Share on other sites

lucian,

 

just wanted to thank you and let you know that the snippet you posted absolutely helped.

now we could generate a .jrxml file for an existing .jasper file.

 

:)

 

thanks, lucian.

 

 

edwin

 

for the working java file refer to the url below:

http://www.jasperforge.org/index.php?option=com_joomlaboard&Itemid=215&func=view&id=26119&catid=8

 

Post edited by: redwine, at: 2007/06/07 21:51

Link to comment
Share on other sites

  • 2 weeks later...

Hi master

Sir I use sun java studio creator with oracle and for reporting I use ireport

 

 

Sir I use this code for creating the pdf file

 

See my cod

 

 

public String button1_action() {

Connection conn = null ;

log("*********** connecting");

try {

javax.naming.Context ctx = new javax.naming.InitialContext() ;

DataSource ds = (DataSource)ctx.lookup(" java:comp/env/jdbc/datasource1" ) ;

conn = ds.getConnection() ;

} catch (Exception ex) {

error(" Error counting rows: " + ex.getMessage() );

log(" Error counting rows: " + ex.getMessage() );

}

 

JasperReport jasperReport;

JasperPrint jasperPrint;

 

log("compiling report");

try {

jasperReport = JasperCompileManager.compileReport("C:/mfa.jasper");

 

} catch (Exception ex) {

log(" ********* Error compiling report: " + ex.getMessage() );

}

 

return null;

}

 

 

but compliemanager give me error

 

 

1. Invalid byte 1 of 1-byte UTF-8 sequence

 

 

see my error ( Invalid byte 1 of 1-byte UTF-8 sequence ) detail [#|2007-06-16T15:22:44.761+0500|INFO|sun-appserver-pe8.2|javax.enterprise.system.container.web|_ThreadID=21;|WebModule[/WebApplication17] ********* Error compiling report: com.sun.org.apach by mfa

 

 

 

2. Illegal character in path at index 18:

 

Caused by: java.net.URISyntaxException: Illegal character in path at index 18: file:/C:/Documents and Settings/Administrator/My Documents/Creator/Projects/WebApplication15/build/web/WEB-INF/lib/log4j-core.jar

at java.net.URI$Parser.fail(URI.java:2809)

at java.net.URI$Parser.checkChars(URI.java:2982)

at java.net.URI$Parser.parseHierarchical(URI.java:3066)

at java.net.URI$Parser.parse(URI.java:3014)

at java.net.URI.(URI.java:578)

at com.sun.enterprise.loader.EJBClassLoader$URLEntry.init(EJBClassLoader.java:848)

... 16 more

|#]

 

 

 

 

Please give me idea how I create pdf file

 

Thank’s

 

aamir

Link to comment
Share on other sites

  • 3 years later...

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;

class ConvertJasperJrxml {

        public static String sourcePath, destinationPath, xml;

        public static JasperDesign jd = new JasperDesign();

        public static void main(String[] args) {

                sourcePath = "C:TesteFile.jasper";

                destinationPath = "C:TesteFile.jrxml";

                try {

                        JasperReport report = (JasperReport) JRLoader.loadObject(sourcePath);

                        JRXmlWriter.writeReport(report, destinationPath, "UTF-8");

                } catch (JRException e) {

                        e.printStackTrace();

                }

         }

}



Post Edited by alekingo at 08/25/2010 13:04
Link to comment
Share on other sites

  • 2 months later...

I found there's a limit to how far back it can convert. I tried opening a .jasper file created in 1.3.3 and it failed. However I took the same .jasper file created in 3.5 and it was able to open the file. Non the less an interesting feature. I wonder when they introduced it.

Link to comment
Share on other sites

  • 3 months later...

I have a set of compiled JasperReports (*.jasper files).  How can I determine which version of Jasper (ex. 4.0.0) was used to compile each report?  I took a quick look at the JasperReport class/object for a property that sounded like what I was looking for but no luck ;-(

Link to comment
Share on other sites

  • 1 year later...

Lucian, Please could help me with a piece of code that can dynamically load an image and add it as part of a .japser file. the below code is the best that I have been able to come up with:

 

image = new JRDesignImage(jasperDesign);

image.setScaleImage(ScaleImageEnum.RETAIN_SHAPE);

image.setHorizontalAlignment(HorizontalAlignEnum.CENTER);

image.setVerticalAlignment(VerticalAlignEnum.JUSTIFIED);

image.setEvaluationTime(EvaluationTimeEnum.NOW);

image.setEvaluationGroup(group);

image.setHyperlinkType(HyperlinkTypeEnum.NONE);

image.setHyperlinkTarget(HyperlinkTargetEnum.SELF);

image.setLazy(false);

image.setX(0);//imageWidth + 10);

image.setY(5);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{" + new File(AppsContextListener.getDataDirectory(), "btk.jpg").getAbsolutePath() + "}");

image.setExpression(expression);

band.addElement(image);

 

Your help and assistance will be greatly appreciated and thanks for that piece of code, it really helped.

Link to comment
Share on other sites

  • 1 year later...

Is there someone who can explain me how I have to run this code? Can this be done inside Jaspersoft Studio? 

(I'm also stuck with a report only in .jasper format (somehow I managed to delete it) and to use it with Jaspersoft server it seems that I need  .jrxml format)

 

(FYI.... I'm a JAVA noob.....)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...