Ma tâche consiste à extraire une paire (nom, valeur par défaut) de tous les attributs facultatifs d'un type complexe donné. J'ai le morceau de code suivant:Apache Xerces lance java.lang.NoSuchMethodError lors de l'utilisation de XSAttributeUse.getValueConstraintValue()
XSObjectList attrList = typeDefinition.getAttributeUses();
for (int i = 0; i < attrList.getLength(); i++) {
XSAttributeUse attributeUse = (XSAttributeUse) attrList.item(i);
if (!attributeUse.getRequired()) {
String name = attributeUse.getValueConstraintValue().getNormalizedValue();
String value = /* extracting the default value */;
}
}
Ce produit l'erreur:
Exception in thread "main" java.lang.NoSuchMethodError: org/apache/xerces/xs/XSAttributeUse.getValueConstraintValue()Lorg/apache/xerces/xs/XSValue; (loaded from path\to\sdk\jre\lib\xml.jar by <Bootstrap Loader>) called from class my.package.xsd.XSDParser (loaded from file:/path/to/the/project/SwidSigner/target/classes/ by [email protected]).
at my.package.xsd.XSDParser.getTypeAttributes(XSDParser.java:54)
at my.package.xsd.XSDParser.getAttributes(XSDParser.java:37)
at my.package.Main.main(Main.java:29)
Quoi de plus, quand je change à:
XSObjectList attrList = typeDefinition.getAttributeUses();
for (int i = 0; i < attrList.getLength(); i++) {
XSAttributeUse attributeUse = (XSAttributeUse) attrList.item(i);
XSAttributeDeclaration attributeDecl = attributeUse.getAttrDeclaration();
if (!attributeUse.getRequired()) {
String name = attributeDecl.getValueConstraintValue().getNormalizedValue();
String value = /* extracting the default value */;
}
}
L'erreur se produit encore, mais il se plaint de la classe XSAttributeDeclaration à la place. Il n'y a pas d'erreur lors de l'utilisation d'autres méthodes, telles que
XSComplexTypeDefinition.getAttributeUses()
J'utilise Maven pour importer Xerces:
<dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
<version>2.11.0</version>
</dependency>
Quelle version de Java utilisez-vous? Il semble qu'il tente de charger une classe Xerces à partir du répertoire lib de votre JRE. – rmlan
J'utilise Java 8. Comment charger la classe Xerces de Maven? –