users@jaxb.java.net

JAXB 2 samples, Maven, LinkageError

From: John Sanda <john.sanda_at_gmail.com>
Date: Mon, 19 Jun 2006 13:36:56 -0400

I recently downloaded the JAXB 2.0.1 RI and started going through a
couple of the samples. I came across the Maven plugin for xjc, and I
decided to set up Maven builds for the samples, which I thought I
might later post back to this list or the Maven users list. I
apologize if I am posting on the wrong list, but I thought my
question(s) might be better suited here as opposed to the Maven users
list.

I am having a problem in the create-marshal sample of the JAXB RI.
When I try to run the program through Maven (using the exec plugin
from mojo.codehaus.org), I get a LinkageError. Here is my pom.xml.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.redhat</groupId>
  <artifactId>create-marshal</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>Maven Quick Start Archetype</name>
  <url>http://maven.apache.org</url>

 <repositories>
    <repository>
      <id>java.net</id>
      <name>java.net Maven Repository</name>
      <url>https://maven-repository.dev.java.net/nonav/repository</url>
      <layout>legacy</layout>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>

    <repository>
      <id>Maven Snapshots</id>
      <url>http://snapshots.maven.codehaus.org/maven2/</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
  </repository>
  </repositories>

  <pluginRepositories>
    <pluginRepository>
      <id>Maven Snapshots</id>
      <url>http://snapshots.maven.codehaus.org/maven2/</url>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <releases>
        <enabled>false</enabled>
      </releases>
    </pluginRepository>
  </pluginRepositories>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!--
    <dependency>
      <groupId>javax.xml.bind</groupId>
      <artifactId>jaxb-api</artifactId>
      <version>2.0</version>
      <scope>compile</scope>
    </dependency>
    -->

    <dependency>
      <groupId>com.sun.xml.bind</groupId>
      <artifactId>jaxb-impl</artifactId>
      <version>2.0</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>com.sun.tools.xjc.maven2</groupId>
        <artifactId>maven-jaxb-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>generate</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <schemaDirectory>src/main/resources/xsd</schemaDirectory>
          <generatePackage>primer.po</generatePackage>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>java</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <mainClass>Main</mainClass>
          <systemProperties>
            <systemProperty>
              <key>dummyKey</key>
              <value>dummyValue</value>
            </systemProperty>
          </systemProperties>
        </configuration>
      </plugin>
   </plugins>
  </build>
</project>


I have the dependency for jaxb-api commented out since that dependency
is satisfied by jaxb-impl, which I of course need to run the program.
I should note that I have no problems generating the binding classes
or compiling the source. To run Main, I issue the following at a
command prompt

mvn exec:java

Here is a snippet from the stacktrace.

Caused by: java.lang.LinkageError: loader constraints violated when
linking javax/xml/namespace/QName class
        at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.<clinit>(RuntimeBuiltinLeafInfoImpl.java:186)
        at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init>(RuntimeTypeInfoSetImpl.java:25)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:78)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:41)
        at com.sun.xml.bind.v2.model.impl.ModelBuilder.<init>(ModelBuilder.java:97)
        at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.<init>(RuntimeModelBuilder.java:44)
        at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:343)
        at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:215)
        at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:76)
        at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:55)
        at com.sun.xml.bind.v2.ContextFactory.createContext(ContextFactory.java:124)
        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:585)
        at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:132)
        at javax.xml.bind.ContextFinder.find(ContextFinder.java:286)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
        at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:244)
        at Main.main(Main.java:59)

I know that JAXB 2 requires Java 5, and the LinkageError makes me
think that somehow attempting to use classes compiled for an earlier
release.
-- 
- John