IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Format d'échange (XML, JSON...) Java Discussion :

jaxb-impl : Quand l'utilisation de ce jar (en plus de jaxb-api) devient necessaire? [JAXB]


Sujet :

Format d'échange (XML, JSON...) Java

  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2009
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2009
    Messages : 76
    Par défaut jaxb-impl : Quand l'utilisation de ce jar (en plus de jaxb-api) devient necessaire?
    Bonjour,

    Quand l'utilisation du jar jaxb-impl (en plus de jaxb-api) devient nécessaire?

    car pour les besoins que j'ai actuellement je n'en ai pas besoin du jaxb-impl et en plus ça m'évite une exception (PropertyException: name: com.sun.xml.internal.bind.namespacePrefixMapper) quand je veux toucher aux namespace préfixe.

    juste pour info, quand j'ai eu cette exception, j'utilisais les jar suivants, déclarés comme suit dans mon pom:

    <dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.2</version>
    <type>jar</type>
    <scope>compile</scope>
    </dependency>

    <dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.1.12</version>
    <type>jar</type>
    <scope>compile</scope>
    </dependency>
    et du coup j'ai dû abandonner le jaxb-impl

    Merci d'avance

  2. #2
    Membre confirmé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2009
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2009
    Messages : 76
    Par défaut
    Je suis passé à la version 2.2 du jaxb-impl et rien, toujours une exception:




    Sous eclipse j'ai :
    javax.xml.bind.PropertyException: name: com.sun.xml.internal.bind.namespacePrefixMapper value: export.xml.aveclist.ElementComposeAccess$1@120bf2c
    at javax.xml.bind.helpers.AbstractMarshallerImpl.setProperty(AbstractMarshallerImpl.java:338)
    at com.sun.xml.bind.v2.runtime.MarshallerImpl.setProperty(MarshallerImpl.java:533)
    at export.xml.aveclist.ElementComposeAccess.marshal(ElementComposeAccess.java:34)
    at export.xml.aveclist.ElementComposeRepository.write(ElementComposeRepository.java:58)
    at export.xml.aveclist.TestJaxbElementCompose.main(TestJaxbElementCompose.java:17)
    DefaultValidationEventHandler: [FATAL_ERROR]: Premature end of file.
    Location: line 1
    javax.xml.bind.UnmarshalException
    - with linked exception:
    [org.xml.sax.SAXParseException: Premature end of file.]
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.createUnmarshalException(AbstractUnmarshallerImpl.java:315)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.createUnmarshalException(UnmarshallerImpl.java:514)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:215)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:184)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:137)
    at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:194)
    at export.xml.aveclist.ElementComposeAccess.unmarshal(ElementComposeAccess.java:50)
    at export.xml.aveclist.ElementComposeRepository.read(ElementComposeRepository.java:23)
    at export.xml.aveclist.TestJaxbElementCompose.main(TestJaxbElementCompose.java:19)
    Caused by: org.xml.sax.SAXParseException: Premature end of file.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(ErrorHandlerWrapper.java:174)
    at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:388)
    at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(XMLScanner.java:1414)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:1059)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648)
    at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140)
    at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:510)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:807)
    at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737)
    at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:107)
    at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1205)
    at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:522)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:211)
    ... 6 more
    Exception in thread "main" java.lang.NullPointerException
    at export.xml.aveclist.TestJaxbElementCompose.main(TestJaxbElementCompose.java:21)


    en ligne de commande quand j'execute : mvn clean install, j'obtient:

    [ERROR] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Compilation failure

    C:\doaat-sime\appli\muppet\head\ws\ze-testJaxb-export\src\main\java\export\xml\aveclist\ElementComposeAccess.java:[13,43] package com.sun.xml.internal.bind.marshaller does not exist

    C:\doaat-sime\appli\muppet\head\ws\ze-testJaxb-export\src\main\java\export\xml\aveclist\ElementComposeAccess.java:[25,4] cannot find symbol
    symbol : class NamespacePrefixMapper

    location: class export.xml.aveclist.ElementComposeAccess

    C:\doaat-sime\appli\muppet\head\ws\ze-testJaxb-export\src\main\java\export\xml\aveclist\ElementComposeAccess.java:[25,39] cannot find symbol
    symbol : class NamespacePrefixMapper
    location: class export.xml.aveclist.ElementComposeAccess

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2009
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2009
    Messages : 76
    Par défaut
    Finalement je suis passé aux versions 2.2.4

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
     
    <dependency>
                <groupId>javax.xml.bind</groupId>
                <artifactId>jaxb-api</artifactId>
                <version>2.2.4</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
     
            <dependency>
                <groupId>com.sun.xml.bind</groupId>
                <artifactId>jaxb-impl</artifactId>
                <version>2.2.4</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>

    Si vous rencontreriez le problème suivant en compilant:

    C:\....\head\ws\ze-testJaxb>mvn clean install
    [INFO] Scanning for projects...
    [INFO] ------------------------------------------------------------------------
    [INFO] Building Unnamed - ze-testJaxb-export:ze-testJaxb-export:jar:0.0.1-SNAPSHOT
    [INFO] task-segment: [clean, install]
    [INFO] ------------------------------------------------------------------------
    [INFO] [clean:clean {execution: default-clean}]
    [INFO] Deleting directory C:\doaat-sime\appli\muppet\head\ws\ze-testJaxb-export\target
    [INFO] [resources:resources {execution: default-resources}]
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
    [INFO] Copying 2 resources
    Downloading: http://geodearretdev.edf.fr:8888/sha...t-parent-1.pom
    [INFO] Unable to find resource 'net.java:jvnet-parent:pom:1' in repository central (http://repo1.maven.org/maven2)
    [INFO] ------------------------------------------------------------------------
    [ERROR] BUILD ERROR
    [INFO] ------------------------------------------------------------------------
    [INFO] Error building POM (may not be this project's POM).

    car on passe par des proxy (sécurité de mon client)

    dans ce cas là sous:.m2/repository\net\java créer un jvnet-parent\1 et télécharger le jvnet-parent-1.pom


    autre chose dans la méthode marchal j'avais

    marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", mapper);
    que j'ai dû changé en "com.sun.xml.bind.namespacePrefixMapper" car l'import du NamespacePrefixMapper provient de com.sun.xml.bind.marshaller (jaxb-impl) et non le jdk (.internal.)

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    
    public void marshal(final ElementCompose elementCompose, final OutputStream output)
       ...
    ...   
        NamespacePrefixMapper mapper = new NamespacePrefixMapper() {
    		@Override
    		public String getPreferredPrefix(String namespaceUri, String suggestion, boolean requirePrefix) {
    			if ("http://toto/titi/tutu".equals(namespaceUri)) {
    				return "p";
    			}
    			return suggestion;
    		}
    	};
    /*marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", mapper);*/ 
    	marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", mapper);    // Avec cette ligne ça marche
        
       
    }


    car l'implémentation de AbstractMarshallerImpl utilisé : com.sun.xml.bind.v2.runtime.MarshallerImpl
    et la constante qui existe dans cette classe


    protected static final String PREFIX_MAPPER = "com.sun.xml.bind.namespacePrefixMapper"; et non pas com.sun.xml.internal.bind.namespacePrefixMapper

  4. #4
    Membre confirmé
    Homme Profil pro
    Développeur Java
    Inscrit en
    Octobre 2009
    Messages
    76
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Java

    Informations forums :
    Inscription : Octobre 2009
    Messages : 76
    Par défaut
    Le souci n'est pas lié à la version mais au conflit entre import que je faisais à partir du jaxb-impl : import com.sun.xml.bind.marshaller.NamespacePrefixMapper;
    et entre la constante recherché : marshaller.setProperty("com.sun.xml.internal.bind.namespacePrefixMapper", mapper);

    je viens de re-tester avec la configuration initiale
    <artifactId>jaxb-api</artifactId>
    <version>2.2</version>


    <artifactId>jaxb-impl</artifactId>
    <version>2.1.12</version>
    et ça marche.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. SqlException quand j utilise Java -jar
    Par parou dans le forum NetBeans
    Réponses: 1
    Dernier message: 03/10/2006, 12h01
  2. [Struts-Layout] exception quand j'utilise <layout:submit&
    Par jahjah42 dans le forum Struts 1
    Réponses: 2
    Dernier message: 29/11/2005, 11h17
  3. "sauter" un champ quand on utilise la tabulation
    Par jisse dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 18/09/2005, 01h42
  4. [Applet] Utilisation d'un jar
    Par calypso dans le forum Applets
    Réponses: 2
    Dernier message: 25/03/2005, 11h23
  5. [JAR]Problème utilisation manifest et jar
    Par doudine dans le forum Eclipse Java
    Réponses: 6
    Dernier message: 07/01/2005, 10h21

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo