IllegalArgumentException:当使用Objects数组作为SCHEMA_SOURCE属性的值时,没有两个Schema应该共享同一个targetNamespace

时间:2011-08-27 07:48:26

标签: java jasper-reports ireport xerces jaxp

我正在使用JasperReport / ireport4, 我试图生成如下报告

public void fillReport() throws ParseException, groovyjarjarcommonscli.ParseException, IOException {

    try {
        Driver monDriver = new com.mysql.jdbc.Driver();
        DriverManager.registerDriver(monDriver);
        connection = (Connection) DriverManager.getConnection("jdbc:mysql://localhost:3306/MyDB","", "");
        Map mymap = new HashMap();
        mymap.put("Title", MyTitle);
        mymap.put("legend", legend);
        mymap.put("SQL", Query());
        FacesContext facesContext = FacesContext.getCurrentInstance();
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
        InputStream reportStream = facesContext.getExternalContext().getResourceAsStream("C:/Documents and Settings/report2.jasper");
        ServletOutputStream servletOutputStream = response.getOutputStream();
        facesContext.responseComplete();
        response.setContentType("C:/Documents and Settings/report2.pdf");
        JasperRunManager.runReportToPdfStream(reportStream, servletOutputStream, mymap, connection);
        connection.close();
        servletOutputStream.flush();
        servletOutputStream.close();
    } catch (JRException e) {

        e.printStackTrace();}
}

但发生了错误。

Caused by: java.lang.IllegalArgumentException:  When using array of Objects as the value of SCHEMA_SOURCE property , no two Schemas should share the same targetNamespace. 
    at org.apache.xerces.impl.xs.XMLSchemaLoader.processJAXPSchemaSource(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.findSchemaGrammar(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
    at org.apache.xerces.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
    at org.apache.xerces.impl.XMLNSDocumentScannerImpl$NSContentDispatcher.scanRootElementHook(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
    at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
    at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
    at org.apache.commons.digester.Digester.parse(Digester.java:1647)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:241)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.loadXML(JRXmlLoader.java:228)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:216)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:170)
    at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:154)
    at DAOKPI.Bean.fillReport(Bean.java:1139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:737)
    at javax.el.BeanELResolver.invoke(BeanELResolver.java:467)
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:254)
    at com.sun.el.parser.AstValue.invoke(AstValue.java:228)
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:148)
    ... 34 more

这是我的图书馆

enter image description here

3 个答案:

答案 0 :(得分:2)

对于使用maven遇到此错误的任何人:

找出哪个依赖项依赖于xercesImpl.jar,并在POM中为给定的依赖项添加一个排除项,如下所示:

<dependency>
    ...
    <exclusions>
    <exclusion>
        <groupId>xerces</groupId>
        <artifactId>xercesImpl</artifactId>
        </exclusion>
    </exclusions>
</dependency>

就我而言,麻烦制造者的依赖是jts,所以这就是我的依赖声明现在的样子:

<dependency>
    <groupId>com.vividsolutions</groupId>
    <artifactId>jts</artifactId>
    <version>1.11</version>
    <exclusions>
        <exclusion>
            <groupId>xerces</groupId>
            <artifactId>xercesImpl</artifactId>
            </exclusion>
    </exclusions> 
</dependency>

如果您使用的是m2eclipse,则可以在POM编辑器的 Dependency Hierarchy 选项卡上找到哪个依赖项导入xercesImpl.jar

答案 1 :(得分:0)

你的类路径中有xerces.jar吗?因为JasperReports已经有一个,如果你有一个旧版本,那么可能会有冲突。如果是这样,那么请尝试仅使用JR提供的那个。

答案 2 :(得分:0)

$cmd = escapeshellcmd('sudo mysql -u root -e "create database somedb"');
$test = shell_exec($cmd);

var_dump($test);

使用maven添加此依赖项。它将解决问题。