Sakura Hana Posted March 5, 2014 Share Posted March 5, 2014 Hi everyone!!!I would like ask your help for some solutions.I want to know how can I print report from jasperserver repository.I spent time googling for a period of time, but still cannot get it solve.I got this source, but it does not work. Can someone fix it? package com.src.report;import java.util.HashMap;import java.util.List;import java.util.Locale;import java.util.Map;import net.sf.jasperreports.engine.JasperPrint;import net.sf.jasperreports.view.JasperViewer;import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ResourceDescriptor;import com.jaspersoft.jasperserver.irplugin.JServer;import com.jaspersoft.jasperserver.irplugin.wsclient.WSClient;public class PrintService { private static JServer server = null; public static void ConnectionString(String webServiceUrl, String username, String password){ server = new JServer(); server.setUsername(username); server.setPassword(password); server.setUrl(webServiceUrl); } public static void runReports(String webServiceUrl, String username, String password) throws Exception{ ConnectionString(webServiceUrl, username, password); WSClient client = new WSClient(server); ResourceDescriptor resourceDescriptor = new ResourceDescriptor(); resourceDescriptor.setUriString ("/reports/samples/EmployeeAccounts"); Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("MY_PARAMETER_NAME", "myparametervalue"); JasperPrint printer = client.runReport(resourceDescriptor, parameterMap); JasperViewer.viewReport(printer, false, Locale.ENGLISH); } public static void main(String[] args) throws Exception { String webServiceUrl = "http://localhost:8080/jasperserver-pro/services/repository"; String username = "jasperadmin"; String password = "jasperadmin"; runReports(webServiceUrl, username, password); }}[/code]Any ideas? please help me. Link to comment Share on other sites More sharing options...
fcerbell Posted March 5, 2014 Share Posted March 5, 2014 Hi, if you installed iReport, in <installdir>/demo/samples, you have a lot of examples. If you want to use this sample code, you have to add some JAR files distributed with iReport.But if you could explain "it does not work", you could have a more detailed answer Link to comment Share on other sites More sharing options...
hozawa Posted March 5, 2014 Share Posted March 5, 2014 What's the error message you're getting and which version of JasperReports and Server are you using? I, also, recommend using REST interface instead of SOAP. BTW, you won't need iReport to run your sample. Link to comment Share on other sites More sharing options...
Sakura Hana Posted March 6, 2014 Author Share Posted March 6, 2014 @fcerbell, I already checked in {ireport}/demo/sample directory. I notice one sample, {ireport}/demo/sample/printservice. It can be helpful, but it is print report from local file not from Jasperserver. By the way, regarding to my code, I got error message like this: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractDOMParser at com.jaspersoft.jasperserver.irplugin.wsclient.WSClient.(WSClient.java:73) at com.src.report.PrintService.runReports(PrintService.java:37) at com.src.report.PrintService.main(PrintService.java:51) Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.AbstractDOMParser at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 3 more Any ideas? Link to comment Share on other sites More sharing options...
Sakura Hana Posted March 6, 2014 Author Share Posted March 6, 2014 @hozawa, actually, If I can run my own code, I will create my dependence application for printing report form jasperserver. And regarding to my code, I got these error message: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractDOMParser at com.jaspersoft.jasperserver.irplugin.wsclient.WSClient.(WSClient.java:73) at com.src.report.PrintService.runReports(PrintService.java:37) at com.src.report.PrintService.main(PrintService.java:51) Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.AbstractDOMParser at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 3 more Link to comment Share on other sites More sharing options...
Sakura Hana Posted March 6, 2014 Author Share Posted March 6, 2014 My purpose is to catch report from jasperserver and print it out. If I can run my own code, I will create my dependence application for printing report form jasperserver. Link to comment Share on other sites More sharing options...
hozawa Posted March 16, 2014 Share Posted March 16, 2014 >Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractDOMParser Just as the error messages say. You're missing xerces xml parser jar file in your build path. You'll need it in your lib folder in your application. Link to comment Share on other sites More sharing options...
Sakura Hana Posted March 21, 2014 Author Share Posted March 21, 2014 That's great. Thank you so much for giving me direct clues. Link to comment Share on other sites More sharing options...
Sakura Hana Posted March 21, 2014 Author Share Posted March 21, 2014 As I googled for a period of time, I have found some solution related to my question above. My purpose here is not for reputation or anything else, but just wanna tell someone who get the same issue as I did.My solution is here:1/ Requirement Jar Files:activation-1.1.jaraxis-1.3.jaractivation-1.1.jar axis-1.3.jarcommons-codec-1.5.jarcommons-collections-3.2.jarcommons-digester-1.7.jarcommons-discovery-0.4.jarcommons-logging-1.1.3.jarcommons-logging-1.1.3-javadoc.jarcommons-logging-1.1.3-sources.jarcommons-logging-adapters-1.1.3.jarcommons-logging-api-1.1.3.jarjasperreports-5.2.0.jarjasperserver-common-ws-5.2.0.jarjasperserver-ireport-plugin-2.0.1.jarjaxrpc.jarmail-1.4.jarsaaj.jarwsdl4j-1.5.1.jar2/ Coding:/** To change this template, choose Tools | Templates* and open the template in the editor.*/package jaspersoft.src.jasperprint;import net.sf.jasperreports.engine.JasperPrint;import com.jaspersoft.jasperserver.irplugin.JServer;import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.*;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.logging.Level;import java.util.logging.Logger;import javax.print.PrintService;import javax.print.PrintServiceLookup;import net.sf.jasperreports.engine.JRException;import net.sf.jasperreports.engine.JRExporter;import net.sf.jasperreports.engine.JRExporterParameter;import net.sf.jasperreports.engine.export.JRPrintServiceExporter;import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter;/**** @author Administrator*/public class JasperPrintTest { private static JServer server = null; public JasperPrintTest(String webServiceUrl, String username, String password){ server = new JServer(); server.setUsername(username); server.setPassword(password); server.setUrl(webServiceUrl); } public List list(String uri) throws Exception{ ResourceDescriptor rd = new ResourceDescriptor(); rd.setWsType(ResourceDescriptor.TYPE_FOLDER); rd.setUriString(uri); return server.getWSClient().list(rd); } public ResourceDescriptor get(String uri) throws Exception{ return get(uri, null); } public ResourceDescriptor get(String uri, List arg) throws Exception{ ResourceDescriptor rd = new ResourceDescriptor(); rd.setWsType(ResourceDescriptor.TYPE_REPORTUNIT); rd.setUriString(uri); return server.getWSClient().get(rd, null,arg); } public JasperPrint runReports(String reportUnit, Map params) throws Exception{ ResourceDescriptor rd = new ResourceDescriptor(); rd.setWsType(ResourceDescriptor.TYPE_REPORTUNIT); rd.setUriString(reportUnit); return server.getWSClient().runReport(rd, params); } /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { // TODO code application logic here String webServiceUrl="http://localhost:8080/jasperserver-pro/services/repository"; String username= "jasperadmin"; String password = "jasperadmin"; String printer = "Foxit Reader PDF Printer"; String reporturi = "/reports/samples/AllAccounts"; //reporturi = "/reports/samples/Supreports"; JasperPrintTest object = new JasperPrintTest(webServiceUrl,username,password); JasperPrint jasperPrint = new JasperPrint(); Map parameterMap = new HashMap(); try { jasperPrint = object.runReports(reporturi, parameterMap); } catch (Exception ex) { Logger.getLogger(ClassForm.class.getName()).log(Level.SEVERE, null, ex); } PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); PrintService printService = null; for(PrintService ps : printServices){ if(ps.getName().equals(printer)){ printService = ps; break; } } if(printService !=null) { JRExporter jrExporter = new JRPrintServiceExporter(); jrExporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint); jrExporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE, printService); jrExporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printService.getAttributes()); jrExporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE); jrExporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.TRUE); try { jrExporter.exportReport(); } catch (JRException ex) { Logger.getLogger(ClassForm.class.getName()).log(Level.SEVERE, null, ex); } } else { System.out.println("Printer is not defined"); } }}3/Result:Note: but everything is still not dynamic because it seem cannot usewith input controls (single select, multi-select, etc).If anyone can expand, please help add more. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now