【问题标题】:Print Report from JasperReports Server Repository从 JasperReports 服务器存储库打印报告
【发布时间】:2014-03-05 09:49:49
【问题描述】:

我想请你帮忙解决一些问题。 我想知道如何从 jasperserver 存储库打印报告。 我花时间谷歌搜索了一段时间,但仍然无法解决。 我得到了这个来源,但它不起作用。有人可以修复它吗? 有什么想法吗?请帮帮我。

1.这里是源代码:

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);
    }
}

2.这是错误信息:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractDOMParser
at com.jaspersoft.jasperserver.irplugin.wsclient.WSClient.<init>(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

【问题讨论】:

  • 如果您使用收到的错误消息更新问题(或者如果没有错误消息则说明您看到的问题),我们将更容易为您提供帮助。 Brgds,罗伯
  • @Rob Kielty,我已经更新了问题。有任何想法吗?请帮帮我。

标签: java jasper-reports noclassdeffounderror jasperserver


【解决方案1】:

你可以使用jasper的rest api 很简单:

http://&lt;host&gt;:8080/jasperserver-pro/rest_v2/reports/pathofReport/reportID.format?j_username=username&amp;j_password=password

Refer to this

【讨论】:

    【解决方案2】:

    我用谷歌搜索了一段时间,找到了一些与上述问题相关的解决方案。我在这里的目的不是为了声誉或其他任何事情,而只是想告诉与我遇到同样问题的人。

    我的解决方案在这里:

    1/ 需求 Jar 文件:

    1. activation-1.1.jar
    2. axis-1.3.jar
    3. activation-1.1.jar axis-1.3.jar
    4. commons-codec-1.5.jar
    5. commons-collections-3.2.jar
    6. commons-digester-1.7.jar
    7. commons-discovery-0.4.jar
    8. commons-logging-1.1.3.jar
    9. commons-logging-1.1.3-javadoc.jar
    10. commons-logging-1.1.3-sources.jar
    11. commons-logging-adapters-1.1.3.jar
    12. commons-logging-api-1.1.3.jar
    13. jasperreports-5.2.0.jar
    14. jasperserver-common-ws-5.2.0.jar
    15. jasperserver-ireport-plugin-2.0.1.jar
    16. jaxrpc.jar
    17. mail-1.4.jar
    18. saaj.jar
    19. wsdl4j-1.5.1.jar

    2/ 编码:

    /*
    * 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";
    
    
        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/ 结果:

    注意:但一切仍然不是动态的。请注意。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-11
      相关资源
      最近更新 更多