简体   繁体   English

如果某些内容发生了变化,JAXB maven插件是否只能生成源代码?

[英]Can JAXB maven plugin only generate sources if something has changed?

What happens for me is that every time there is a maven build, all my files get regenerated. 对我来说,每次有maven构建时,我的所有文件都会重新生成。 I don't want that since i have made no changes to my .xsd file and what happens is that, because they were regenerated, git treats them as there were changes to those files. 我不希望这样,因为我没有对我的.xsd文件做任何更改,会发生什么,因为它们被重新生成,git会对它们进行处理,因为这些文件有变化。

Here's my configuration: 这是我的配置:

<execution>
  <id>myExecution</id>
  <goals>
<goal>generate</goal>
  </goals>
   <configuration>
     <schemaDirectory>src/main/resources/MySchema.xsd</schemaDirectory>
     <generatePackage>com.mypackage</generatePackage>
     <generateDirectory>src/main/java</generateDirectory>
     <episode>false</episode>
   </configuration>
</execution>

is there a way arround this? 这有什么方法吗?

Never ever write generated source into the src/main/java directory. 永远不要将生成的源写入src / main / java目录。 Just use the default generateDirectory value (${project.build.directory}/generated-sources/xjc) - it's automatically added to the compile sources. 只需使用默认的generateDirectory值($ {project.build.directory} / generated-sources / xjc) - 它会自动添加到编译源中。

It is best practice to place all artifacts generated by the build process into the maven target directory (aka ${project.build.directory}). 最佳做法是将构建过程生成的所有工件放入maven目标目录(也称为$ {project.build.directory})。

Also, I recommend that you use the Codehaus JAXB-2 Maven Plugin as it seems to be much better maintained. 此外,我建议您使用Codehaus JAXB-2 Maven插件,因为它似乎更好地维护。

I'm also looking for the same solution you need. 我也在寻找你需要的相同解决方案。

To avoid time consuming in recompile code each time, in maven i've created two profile. 为了避免每次重新编译代码都耗费时间,我在maven中创建了两个配置文件。

The first profile is used only for re-create classes from XSD: the plugin is inside the profile 第一个配置文件仅用于从XSD重新创建类:插件位于配置文件中

<profile>
  <id>create-from-xsd</id>
  <plugins>
     <plugin>
       ... maven jax plugin ...
     </plugin>
  <plugins>
<profile>

and then the other profile without the plugin. 然后没有插件的其他配置文件。

When I need jax-b, I select the profile 1 and the classes are generated; 当我需要jax-b时,我选择了配置文件1并生成了类; In the other cases I use profile 2. 在其他情况下,我使用配置文件2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM