IllegalArgumentException: When using array of Objects as the value of SCHEMA_SOURCE property , no two Schemas should share the same targetNamespace

时光总嘲笑我的痴心妄想 提交于 2020-03-03 03:41:15

问题


I am using JasperReport/ireport4, I tried to generate a report as below

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

but an error occured.

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

here are my libraries


回答1:


To anyone using maven encountering this error:

Find out which one of your dependencies has a dependency on xercesImpl.jar and add an exclusion to the given dependency in your POM like so:

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

In my case, the troublemaker dependency was jts, so this is what my dependency declaration now looks like:

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

If you are using m2eclipse, you can find which dependency imports xercesImpl.jar on the Dependency Hierarchy tab of the POM editor.




回答2:


Do you have xerces.jar in your classpath? Because JasperReports has one already and if you have an older version then there might be conflicts. If so then try using only the one provided by JR.




回答3:


<dependency>
    <groupId>xerces</groupId>
    <artifactId>xercesImpl</artifactId>
    <version>2.6.0</version>
</dependency>

add this dependency using maven. it will solve the problem.



来源:https://stackoverflow.com/questions/7213219/illegalargumentexception-when-using-array-of-objects-as-the-value-of-schema-sou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!