我想问您一些解决方案的帮助。
我想知道如何从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

最佳答案

您可以利用jasper的其余api
它很简单:

http://<host>:8080/jasperserver-pro/rest_v2/reports/pathofReport/reportID.format?j_username=username&j_password=password

Refer to this

10-08 16:06