我是Maven的新手,我正在尝试使用它从我的XSD生成Java类。
我的xsd文件位于src / main / resources / xsd
中在依赖关系中我有这个,但我认为我不需要它,因为我正在使用Java 1.6
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.0</version>
</dependency>
在构建部分我有
<build>
<pluginManagement>
..
<plugin>
<inherited>true</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
..
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<includeSchemas>
<includeSchema>**/test.xsd</includeSchema>
</includeSchemas>
<generatePackage>com.myproject.adapter.generated</generatePackage>
<bindingDirectory>src/main/binding</bindingDirectory>
<removeOldOutput>true</removeOldOutput>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
但是,当我运行它时,我什么都没得到。 我运行了mvn compile和generate-sources,使用-e和-X标志来查看输出,但似乎没有调用目标。 有什么想法吗?
答案 0 :(得分:2)
首先,您应该始终指定您正在使用的依赖项或插件的版本
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
然后你必须在执行中提供以下条目
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>test.xsd</include>
</schemaIncludes>
这是一个完整的定义,我已经包含了jaxb2-basics插件,因为你几乎总是想要它做什么。
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
<executions>
<execution>
<id>jaxb-test</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<forceRegenerate>true</forceRegenerate>
<schemaDirectory>src/main/resources</schemaDirectory>
<schemaIncludes>
<include>test.xsd</include>
</schemaIncludes>
</configuration>
</execution>
</executions>
<configuration>
<extension>true</extension>
<args>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-Xcopyable</arg>
<arg>-Xmergeable</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.0</version>
</plugin>
</plugins>
</configuration>
</plugin>