Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jaxb2-maven-plugin add classpath to generated sources

Tags:

java

xml

maven

jaxb

I use the codehaus jaxb-maven-plugin to create java classes from xml schemas:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.2</version>
            <executions>
                <execution>
                    <id>xjc</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/my.xsd</source>
                        </sources>                           
                            <packageName>mypackage</packageName>
                    </configuration>
                </execution>
            </executions>
         </plugin>

The classes are generated as expected to target/generated-sources/jaxb, but this path is not added to the classpath.

So, if I use some of generated classes in other (not generated) classes, maven cannot found it during the compile process.

Any ideas? TIA!

like image 796
t777 Avatar asked Mar 12 '16 19:03

t777


People also ask

What is jaxb2 Maven plugin?

JAXB 2 Maven Plugin. Mojo's JAXB-2 Maven plugin is used to create an object graph from XSDs based on the JAXB 2.x implementation and to generate XSDs from JAXB annotated Java classes.

How to add source code to a Maven project?

– Using build-helper-maven-plugin : Add the plugin in pom.xml as shown below. We just need to add the goal add-source and provide the generated code directory under sources to add as source in our project. Add above plugin in your pom.xml, re-execute mvn clean compile, and you should see something similar as shown below:

How to create Java objects using XSD in jaxb2-maven?

Create xsd directory in src/main/resources and copy yours XSD’s into this folder. In this case, we use org.xsd to create java objects By default, jaxb2-maven-plugin scans XSD schema directory src/main/xsd for XML schema files to create Java source code

How to create an executable JAR file using Maven archiver?

If you want to create an executable jar file, you need to configure Maven Archiver accordingly. You need to tell it which main class to use. This is done with the configuration element. Here is a sample pom.xml configured to add the classpath and use the class fully.qualified.MainClass as the main class:


Video Answer


1 Answers

It is a bug in the jaxb2-maven-plugin:

https://github.com/mojohaus/jaxb2-maven-plugin/issues/44

like image 64
t777 Avatar answered Oct 30 '22 12:10

t777