java Maven JAXB 插件只执行一次执行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12213403/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven JAXB plugin executing only one excecution
提问by Paulius Matulionis
I am trying to generated sources from two XSD
schemas. My JAXB
maven plugin looks like this:
我正在尝试从两个XSD
模式生成源。我的JAXB
Maven 插件如下所示:
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
<artifactId>maven-jaxb-plugin</artifactId>
<version>1.1.1</version>
<executions>
<execution>
<id>GenerateKenexa</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<includeBindings>
<includeBinding>**/jaxb-bindings-kenexa.xml</includeBinding>
</includeBindings>
<includeSchemas>
<includeSchema>**/KenexaXMLConfiguration.xsd</includeSchema>
</includeSchemas>
</configuration>
</execution>
<execution>
<id>GenerateTalentQ</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<includeBindings>
<includeBinding>**/jaxb-bindings-talentq.xml</includeBinding>
</includeBindings>
<includeSchemas>
<includeSchema>**/TalentQXMLConfiguration.xsd</includeSchema>
</includeSchemas>
</configuration>
</execution>
</executions>
</plugin>
The first one gets generated fine. But the second one does not. I see in the maven output:
第一个生成得很好。但第二个没有。我在 Maven 输出中看到:
[INFO] --- maven-jaxb-plugin:1.1.1:generate (GenerateKenexa) @ online.tests.management ---
[INFO] Compiling file:/D:/Projects/GTIWebApplications/gti_online_tests_management/src/main/resources/xsd/KenexaXMLConfiguration.xsd
[INFO] Writing output to D:\Projects\GTIWebApplications\gti_online_tests_management\target\generated-sources\xjc
[INFO]
[INFO] --- maven-jaxb-plugin:1.1.1:generate (GenerateTalentQ) @ online.tests.management ---
[INFO] files are up to date
It says that files are up to date, but they aren't even generated. What might be wrong?
它说文件是最新的,但它们甚至没有生成。可能有什么问题?
采纳答案by Paulius Matulionis
I solved the problem. I have changed the maven jaxb
plugin into maven jaxb2
plugin and now everything works. Now my maven configuration looks like this:
我解决了这个问题。我已将 mavenjaxb
插件更改为 mavenjaxb2
插件,现在一切正常。现在我的 Maven 配置如下所示:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<id>GenerateKenexa</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<schemaIncludes>
<include>KenexaXMLConfiguration.xsd</include>
</schemaIncludes>
<generatePackage>com.groupgti.onlinetest.kenexa.jaxb</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/kenexa</generateDirectory>
</configuration>
</execution>
<execution>
<id>GenerateTalentQ</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<schemaIncludes>
<include>TalentQXMLConfiguration.xsd</include>
</schemaIncludes>
<generatePackage>com.groupgti.onlinetest.talentq.jaxb</generatePackage>
<generateDirectory>${project.build.directory}/generated-sources/talentq</generateDirectory>
</configuration>
</execution>
</executions>
</plugin>
回答by Jan Nielsen
For people coming in to this question as I did, a year later :/
对于像我一样提出这个问题的人,一年后:/
The problem persists in maven-jaxb2-plugin aswell, it's probably some sort of bug in 0.8.3. When you generate the files into the same directory, the plugin "thinks" that the files have allready been generated and skips that second execution.
问题仍然存在于 maven-jaxb2-plugin 中,它可能是 0.8.3 中的某种错误。当您将文件生成到同一目录中时,插件“认为”文件已经生成并跳过第二次执行。
I found that in order to generate the second execution you will have to set the argument
我发现为了生成第二次执行,您必须设置参数
<forceRegenerate>true</forceRegenerate>
In the configuration section.
在配置部分。
回答by Grigory Katkov
First, I would recommend to specify separate output folders for each xsd <outputdirectory>${basedir}/target/generated-sources/xjc</outputdirectory>
首先,我建议为每个 xsd 指定单独的输出文件夹 <outputdirectory>${basedir}/target/generated-sources/xjc</outputdirectory>
And second, try to set it up as separate plugin entries, no separate executions:
其次,尝试将其设置为单独的插件条目,没有单独的执行:
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
...
<includeSchema>**/KenexaXMLConfiguration.xsd...
...
</plugin>
<plugin>
<groupId>com.sun.tools.xjc.maven2</groupId>
...
<includeSchema>**/TalentQXMLConfiguration.xsd...
...
</plugin>
回答by Peng Zhang
I am using jaxb2 while still was facing the problem when I reached here. I added the below piece into config from other folks answers and it works now. For previous answers the part that did the trick should be:
我正在使用 jaxb2,但当我到达这里时仍然面临问题。我从其他人的答案中将以下部分添加到配置中,现在可以使用了。对于以前的答案,成功的部分应该是:
<generateDirectory>${project.build.directory}/generated-sources/kenexa</generateDirectory>
Also a unique execution id is needed
还需要一个唯一的执行 ID
<id>GenerateKenexa</id>
But different directories make the code lies into two top level packages, so at last I am using:
但是不同的目录使代码位于两个顶级包中,所以最后我使用了:
<forceRegenerate>true</forceRegenerate>