13

I have a project which uses Apache Xmlbeans for databinding. Currently it is very simple it only has some Schema-Files in src/main/xsd and xsdconfig in src/main/xsdconfig.

I want to include the generated Classes into the generated jar-File. It works if I specify the xmlbeans goal: "mvn xmlbeans:xmlbeans package" --> Creates a Jar with the xmlbeans classes

But I want to do this within the normal build cycle: "mvn package" --> should create a jar with the xmlbeans classes, but won't.

The pom is the following:

<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>org.test</groupId> <artifactId>xmlbeans-maven-test</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>maven-xmlbeans-plugin</artifactId> <version>2.3.3</version> </plugin> </plugins> </pluginManagement> </build> <dependencies> <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>2.4.0</version> <scope>compile</scope> </dependency> </dependencies> </project> 

I tried to bind it manually to the "generate-sources" (And to the "compile" phase, too) phase, but it does not work.

<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>de.leradon</groupId> <artifactId>xmlbeans-maven</artifactId> <version>0.0.1-SNAPSHOT</version> <build> <pluginManagement> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>maven-xmlbeans-plugin</artifactId> <version>2.3.3</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>xmlbeans</goal> </goals> </execution> </executions> </plugin> </plugins> </pluginManagement> </build> <dependencies> <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>2.4.0</version> <scope>compile</scope> </dependency> </dependencies> </project> 

How can I configure the plugin, so that when I run "mvn package" all the generated classes are packaged into the jar?

Greetings, lerad

2 Answers 2

16

If you configure the plugin under pluginManagement, you still need to declare it under plugins. To simplify, I'm not using the pluginManagement in the pom.xml below:

<project> ... <dependencies> ... <dependency> <groupId>org.apache.xmlbeans</groupId> <artifactId>xmlbeans</artifactId> <version>2.4.0</version> <scope>compile</scope> </dependency> </dependencies> <build> <plugins> ... <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>xmlbeans-maven-plugin</artifactId> <version>2.3.3</version> <executions> <execution> <phase>generate-sources</phase> <goals> <goal>xmlbeans</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project> 

With this POM (and some XSD in src/main/xsd which is the default location), running mvn clean package just works (i.e. sources are generated from the XSD, compiled and packaged as part of the build).

Sign up to request clarification or add additional context in comments.

2 Comments

Do we have newer way of doing this? Still this plugin (its quite old) works but it may break in future since no new developments has been carried out
I've just committed the plugin. So XmlBeans 5.0.0 will integrate that feature.
-3

Try this.

<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>xmlbeans-maven-plugin</artifactId> <version>2.3.2</version> <executions> <execution> <id /> <phase>generate-sources</phase> <goals> <goal>xmlbeans</goal> </goals> </execution> </executions> <configuration> <schemaDirectory>src/main/xsd</schemaDirectory> <staleFile>${project.build.directory}/generated-sources/xmlbeans/.staleFlag</staleFile> <verbose>false</verbose> <quiet>false</quiet> <javaSource>1.6</javaSource> </configuration> </plugin> 

1 Comment

An answer with sample code should always include why that code will work where the original poster's didn't.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.