0
我嘗試使用JAXB2 maven插件從一堆.xsd文件生成java代碼。如果我嘗試在一次執行中從所有xsds生成,我會得到org.xml.sax.SAXParseException: 'root' is already defined
。我無法修改xsd文件,因此我需要獨立生成每個文件。我發現下面的POM的配置來實現的是:jaxb2 maven插件和配置裏面的執行標籤
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>jaxb-Execution1</id>
<phase>generate-sources</phase>
<goals><goal>xjc</goal></goals>
<configuration>
<schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
<outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
<staleFile>${jaxbGenerateDirectory}/.staleFlagExecution1</staleFile>
<bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
<bindingFiles>bindings1.xml</bindingFiles>
<schemaFiles>schema1.xsd</schemaFiles>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
<execution>
<id>jaxb-Execution2</id>
<phase>generate-sources</phase>
<goals><goal>xjc</goal></goals>
<configuration>
<schemaDirectory>${jaxbSchemaDirectory}</schemaDirectory>
<outputDirectory>${jaxbGenerateDirectory}</outputDirectory>
<staleFile>${jaxbGenerateDirectory}/.staleFlagExecution2</staleFile>
<bindingDirectory>${jaxbSchemaDirectory}</bindingDirectory>
<bindingFiles>bindings2.xml</bindingFiles>
<schemaFiles>schema2.xsd</schemaFiles>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
但是,這是行不通的。問題是配置不從執行塊內部讀取。這是爲什麼?我正在使用maven 2.2.1。
你有沒有定義的屬性,比如'$ {jaxbSchemaDirectory}'在你的pom.xml中? – flash
@flash是的,我有。我還輸入了沒有任何屬性佔位符的目錄進行測試。問題在於插件忽略了執行塊中的那些配置。 – Devnullable