Ian Will
Ian Will

Reputation: 1052

mvn generate-sources fails, why isn't xml beans on classpath?

I'm trying to generate java classes for OGC KML 2.2 as part of the maven generate-sources process using the org.codehaus.mojo xmlbeans-maven-plugin. The java code appears to be generated correctly, but I get tons of errors during compilation complaining that 'package org.apache.xmlbeans'. XMLBeans is clearly a dependency, it exists in my ~/.m2 repository, and I've been peek in the jar to make sure the classes are there. It looks like XMLBeans is successfully generating java files in target/generated-sources, but somehow its absent from the classpath during compilation.

I've tried changing the scope of the org.apache.xmlbeans dependency, but to no avail.

Here's the pom.xml

  <modelVersion>4.0.0</modelVersion>
  <groupId>net.opengis</groupId>
  <artifactId>ogc-kml</artifactId>
  <version>2.2.0</version>
  <packaging>pom</packaging>
  <name>ogc-kml</name>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>xmlbeans-maven-plugin</artifactId>
        <version>2.3.3</version>
        <executions>
         <execution>
          <goals>
           <goal>xmlbeans</goal>
          </goals>
         </execution>
        </executions>
        <inherited>true</inherited>
        <configuration>
          <download>true</download>
          <schemaDirectory>src/main/xsd</schemaDirectory>
       </configuration>
     </plugin>
    </plugins>
  </build>
  <dependencyManagement>
    <dependencies>

      <dependency>
        <groupId>org.apache.xmlbeans</groupId>
        <artifactId>xmlbeans</artifactId>
        <version>2.6.0</version>
      </dependency>

    </dependencies>
  </dependencyManagement>

The project consists of a single src/main/xsd folder containing the two xsds from http://schemas.opengis.net/kml/2.2.0/. The entire folder structure is at https://github.com/iancw/maven-xmlbeans-question.

I can compile the classes by hand if I put the xmlbeans jar from my ~/.m2 repo on the classpath, e.g.

xmlbeans$ javac -classpath ~/.m2/repository/org/apache/xmlbeans/xmlbeans/2.4.0/xmlbeans-2.4.0.jar org/w3/x2005/atom/*.java org/w3/x2005/atom/impl/*.java net/opengis/kml/x22/*.java x0/oasisNamesTcCiqXsdschemaXAL2/*.java x0/oasisNamesTcCiqXsdschemaXAL2/impl/*.java net/opengis/kml/x22/*.java net/opengis/kml/x22/impl/*.java
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
xmlbeans$ 

I've looked through a number of examples and it seems like I'm doing this right. I haven't seen anyone else complain of this issue. Any maven mavens have suggestions?

(A curious side note is that although i've tried both 2.4.0 and 2.6.0 of the xmlbeans dependency, maven hasn't ever seemed to download the 2.6.0 version into my repository)

Upvotes: 0

Views: 5175

Answers (2)

Greg Domjan
Greg Domjan

Reputation: 14115

One Additional issue that may look similar,
Check your java install jdk and ext folders for older beans jar.
The plugin puts the project dependencies at the end of the classpath.

Upvotes: 0

DB5
DB5

Reputation: 13998

From the POM file that you've included in your question you have only defined the xmlbeans dependency in the dependencyManagement section. You also need to define it in your dependencies section of your POM before it will be included in the classpath at build time.

So for example your POM would be:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>xmlbeans-maven-plugin</artifactId>
            ...
        </plugin>
    </plugins>
</build>
<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.6.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>
<dependencies>
    <groupId>org.apache.xmlbeans</groupId>
    <artifactId>xmlbeans</artifactId>
</dependencies>

Upvotes: 2

Related Questions