2011-09-20 24 views
0

我準備了一些XSD下的src \主\資源文件夾結構,並創建a.jar文件的文件現在我想生成在a.jar文件XSD的scheam對象生成模式Objectsfrom XSD存在於外部jar文件中像generateSource應用另一個應用程序任何人可以幫助我寫在pom.xml文件 的Maven插件一樣什麼都依賴和插件需要。如何使用maven

回答

1

首先你需要提取其中包含XSD使用maven的依賴,插件這樣的罐子。

<plugin> 
<!-- Unpack the jar into target directory --> 
<groupId>org.apache.maven.plugins</groupId> 
<artifactId>maven-dependency-plugin</artifactId> 
<version>2.7</version> 
<executions> 
    <execution> 
     <id>unpack</id> 
     <phase>validate</phase> 
     <goals> 
      <goal>unpack-dependencies</goal> 
     </goals> 
     <configuration> 
          <outputDirectory>${unpack.directory}</outputDirectory> 
      <overWriteIfNewer>true</overWriteIfNewer> 
      <includeGroupIds>com.companyname</includeGroupIds> 
      <includeArtifactIds>jarname</includeArtifactIds> 
      <excludes>**/*.html,samples/**</excludes> 
     </configuration> 
    </execution> 
</executions> 

後來你需要使用Maven的JAXB2-插件下文提到的提取的XSD轉換爲Java類。

<plugin> 
<!-- Convert XSD to java classes using jaxb plugin --> 
<groupId>org.jvnet.jaxb2.maven2</groupId> 
<artifactId>maven-jaxb2-plugin</artifactId> 
<version>0.8.2</version> 
<configuration> 
    <extension>true</extension> 
    <generateDirectory>${generated.source.directory}</generateDirectory> 
</configuration> 
<executions> 
    <execution> 
    <id>Generate java-from-schema</id> 
    <goals> 
     <goal>generate</goal> 
    </goals> 
    <configuration> 
     <schemaDirectory>${unpack.directory}/XXX</schemaDirectory> 
     <catalog>${unpack.directory}/catalog</catalog> 
     <schemaIncludes> 
      <schemaInclude>aaa/*.xsd</schemaInclude> 
      <schemaInclude>bbb/*.xsd</schemaInclude> 
      <schemaInclude>ccc/*.xsd</schemaInclude> 
     </schemaIncludes> 
    </configuration> 
     </execution> 
    </executions>