JAXB-2 Maven Plugin

1. Introduction.

    This plugin uses JAXB2 to generate Java classes from XML Schemas (and binding files) and to create XML Schemas for existing Java classes.

     General Information about the plugin goals:

  • jaxb2:schemagen Creates XML Schema Definition (XSD) file(s) from annotated Java sources.
  • jaxb2:testSchemagen Creates XML Schema Definition (XSD) file(s) from annotated Java test sources.
  • jaxb2:xjc Generates Java sources from XML Schema(s).
  • jaxb2:testXjc Generates Java test sources from XML Schema(s).

2. How to config it in pom.xml

    The following example demonstrates a basic plugin configuration for generating Java sources from XML schemas:

<project>
    ...
    <dependencies>
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.1</version>
        </dependency>
        ...
    </dependencies>
    ...
    <build>
        <pluginManagement>
            <plugins>
                <!-- Need Java 5, which is the default since v2.3 of the maven-compiler-plugin. -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>1.5</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <packageName>com.example.myschema</packageName> <!-- The name of your generated source package -->
                </configuration>
            </plugin>
            ...
        </plugins>
    <build>
    ...
</project>
    In this example, the plugin will generate Java sources from all XML schema files in the default schema directory ( ${project.basedir}/src/main/xsd). The package of the generated sources will be 'com.example.myschema' as defined by the packageName configuration element.

    Attention: the plugin requires at least the Java 5.0 compiler.

4. How to use the plugin in your project.

    See http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/JAXBContext.html

Other references:

    http://mojo.codehaus.org/jaxb2-maven-plugin/index.html
     http://blog.csdn.net/xjtuse_mal/article/details/6930538
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值