Précédent   Forum des professionnels en informatique > Logiciels > Solutions d'entreprise > Business Intelligence > Jasper
Jasper Forum d'entraide sur Jasper Reports. Avant de poster --> FAQ Jasper, Tutoriels Jasper
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 09/03/2008, 11h45   #1
Membre confirmé
 
Inscription : janvier 2007
Messages : 767
Détails du profil
Informations forums :
Inscription : janvier 2007
Messages : 767
Points : 224
Points : 224
Par défaut faire fonctionner l'example XMLDataSourceExample

Bonjour,

je cherche a faire fonctionner l'exmple it.businesslogic.ireport.examples.XMLDataSourceExample
addressbook.jasper
et addressbook.xml
j'en ai trouve sur le Net mais j'ai le message d'erreur
net.sf.jasperreports.engine.JRException: Error loading object from file : c:\prj_java\TestAgarder\jasperxml01\addressbook.jasper
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:92)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:515)
at jasperxml01.Demo3.main(Demo3.java:66)
Caused by: java.io.InvalidClassException: net.sf.jasperreports.engine.base.JRBaseReport; local class incompatible: stream classdesc serialVersionUID = 604, local class serialVersionUID = 10200

je suppose que le fichier .jasper deja serialisé n'est pas compatible avec le Mien, j'ai essayé avec 3 versions de JDK sans succes

Merci d'avance
Philippe
pcouas est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 10/03/2008, 14h07   #2
Membre du Club
 
Avatar de couetbis
 
Inscription : juillet 2005
Messages : 136
Détails du profil
Informations personnelles :
Âge : 29

Informations forums :
Inscription : juillet 2005
Messages : 136
Points : 48
Points : 48
Salut,
Le mieux est de partir du fichier .jrxml et non du .jasper qui est en quelque sorte un "fichier compilé".
Sinon tu as un autre exemple de xmldatasource dans les sources de jasperreports (demo).
couetbis est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/03/2008, 07h13   #3
Membre confirmé
 
Inscription : janvier 2007
Messages : 767
Détails du profil
Informations forums :
Inscription : janvier 2007
Messages : 767
Points : 224
Points : 224
Bonjour

J'ai teste sans succes un autre exemple fournis dans les sources XmlDataSourceApp.java avec northwind.xml .
en taskName j'ai force pdf et en fileName c:\\xx.pdf, Mais
a priori il a besoin que mon fichier resultat existe déja ??

Merci d'avance
Philippe


package jasperxml01;

import net.sf.jasperreports.engine.JRException;

/*
//www.jaspersoft.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* JasperSoft Corporation
* 185, Berry Street, Suite 6200
* San Francisco CA 94107
* http://www.jaspersoft.com
*/
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.JasperPrintManager;
import net.sf.jasperreports.engine.JasperRunManager;
import net.sf.jasperreports.engine.data.JRXmlDataSource;
import net.sf.jasperreports.engine.export.JRCsvExporter;
import net.sf.jasperreports.engine.export.JRXlsExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.util.JRLoader;


/**
* @author Teodor Danciu (teodord@users.sourceforge.net)
* @version $Id: XmlDataSourceApp.java,v 1.7 2005/06/27 07:14:40 teodord Exp $
*/
public class demo2
{


/**
*
*/
private static final String TASK_FILL = "fill";
private static final String TASK_PRINT = "print";
private static final String TASK_PDF = "pdf";
private static final String TASK_XML = "xml";
private static final String TASK_XML_EMBED = "xmlEmbed";
private static final String TASK_HTML = "html";
private static final String TASK_XLS = "xls";
private static final String TASK_CSV = "csv";
private static final String TASK_RUN = "run";


/**
*
*/
public static void main(String[] args)
{
String fileName = null;
String taskName = null;
/*
if(args.length == 0)
{
usage();
return;
}

int k = 0;
while ( args.length > k )
{
if ( args[k].startsWith("-T") )
taskName = args[k].substring(2);
if ( args[k].startsWith("-F") )
fileName = args[k].substring(2);

k++;
}
*/
taskName ="pdf";
taskName ="fill";
fileName="c:\\xx.pdf";

try
{
long start = System.currentTimeMillis();
if (TASK_FILL.equals(taskName))
{
JasperFillManager.fillReportToFile(fileName, null,
new JRXmlDataSource(new BufferedInputStream(new FileInputStream("northwind.xml")), "/Northwind/Customers"));
System.err.println("Filling time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_PRINT.equals(taskName))
{
JasperPrintManager.printReport(fileName, true);
System.err.println("Printing time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_PDF.equals(taskName))
{
JasperExportManager.exportReportToPdfFile(fileName);
System.err.println("PDF creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_XML.equals(taskName))
{
JasperExportManager.exportReportToXmlFile(fileName, false);
System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_XML_EMBED.equals(taskName))
{
JasperExportManager.exportReportToXmlFile(fileName, true);
System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_HTML.equals(taskName))
{
JasperExportManager.exportReportToHtmlFile(fileName);
System.err.println("HTML creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_XLS.equals(taskName))
{
File sourceFile = new File(fileName);

JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".xls");

JRXlsExporter exporter = new JRXlsExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());
exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET, Boolean.TRUE);

exporter.exportReport();

System.err.println("XLS creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_CSV.equals(taskName))
{
File sourceFile = new File(fileName);

JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".csv");

JRCsvExporter exporter = new JRCsvExporter();

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
exporter.setParameter(JRExporterParameter.OUTPUT_FILE_NAME, destFile.toString());

exporter.exportReport();

System.err.println("CSV creation time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else if (TASK_RUN.equals(taskName))
{
JasperRunManager.runReportToPdfFile(fileName, null,
new JRXmlDataSource(new BufferedInputStream(new FileInputStream("northwind.xml")), "/Northwind/Customers"));
System.err.println("PDF running time : " + (System.currentTimeMillis() - start));
System.exit(0);
}
else
{
usage();
System.exit(0);
}
}
catch (JRException e)
{
e.printStackTrace();
System.exit(1);
}
catch (Exception e)
{
e.printStackTrace();
System.exit(1);
}
}


/**
*
*/
private static void usage()
{
System.out.println( "XmlDataSourceApp usage:" );
System.out.println( "\tjava XmlDataSourceApp -Ttask -Ffile" );
System.out.println( "\tTasks : fill | print | pdf | xml | xmlEmbed | html | xls | csv | run" );
}
}



net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException: c:\xx.pdf
at net.sf.jasperreports.engine.util.JRLoader.loadObject(JRLoader.java:75)
at net.sf.jasperreports.engine.JasperFillManager.fillReportToFile(JasperFillManager.java:443)
at jasperxml01.demo2.main(demo2.java:101)
Caused by: java.io.FileNotFoundException: c:\xx.pdf
pcouas est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 11/03/2008, 18h09   #4
Membre du Club
 
Avatar de couetbis
 
Inscription : juillet 2005
Messages : 136
Détails du profil
Informations personnelles :
Âge : 29

Informations forums :
Inscription : juillet 2005
Messages : 136
Points : 48
Points : 48
Salut,
Pour la variable fileName tu dois donner le nom du fichier .jrprint.
Appuie-toi sur ce qu'il y a dans le fichier build.xml
Code :
1
2
3
4
5
6
7
8
 
<target name="pdf" description="Generates a PDF version of the report by converting the .jrprint file.">
		<java classname="${class.name}">
			<arg value="pdf"/>
			<arg value="${file.name}.jrprint"/>
			<classpath refid="classpath"/>
		</java>
	</target>
Ou bien exécute directement le build.xml (ANT). Il faut exécuter les cible (target) javac, compile, fill puis enfin pdf.
couetbis est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/03/2008, 06h18   #5
Membre confirmé
 
Inscription : janvier 2007
Messages : 767
Détails du profil
Informations forums :
Inscription : janvier 2007
Messages : 767
Points : 224
Points : 224
Bonjour

J'ai pus compiler et creer deux fichiers .jasper
CustomerReport.jasper et OrderReport.jasper

Mais lorsque je fais l'option fill j'ai le message d'erreur
et.sf.jasperreports.engine.JRException: java.io.UTFDataFormatException: Invalid UTF8 encoding.
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 net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:90)
at jasperxml01.demo2.main(demo2.java:134)


Merci d'avance philippe
pcouas est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/03/2008, 06h26   #6
Membre confirmé
 
Inscription : janvier 2007
Messages : 767
Détails du profil
Informations forums :
Inscription : janvier 2007
Messages : 767
Points : 224
Points : 224
Ok c'est bon j'ai change dans les fichiers jrxml UTF8 PAR iso8859_1

Merci
pcouas est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 08h39.


 
 
 
 
Partenaires

Hébergement Web