简体   繁体   English

如何配置 IntelliJ IDEA 和/或 Maven 以使用 jaxb2-maven-plugin 生成的 Java 源代码自动添加目录?

[英]How to configure IntelliJ IDEA and/or Maven to automatically add directories with Java source code generated using jaxb2-maven-plugin?

In our project we are using jaxb2-maven-plugin to generate Java source code from XML Schema, which causes that our Maven module requires additional source code directory (in our case target/generated/main/java ).在我们的项目中,我们使用jaxb2-maven-plugin从 XML Schema 生成 Java 源代码,这导致我们的 Maven 模块需要额外的源代码目录(在我们的例子中为target/generated/main/java )。 Up to date I've been using Eclipse and maven-eclipse-plugin to import all the projects into Eclipse workspace.到目前为止,我一直在使用 Eclipse 和maven-eclipse-plugin将所有项目导入 Eclipse 工作区。 The plugin is (somehow) able to add the directory with generated source code automatically to Eclipse' .classpath file.该插件(以某种方式)能够将带有生成的源代码的目录自动添加到 Eclipse 的 .classpath 文件中。

Recently I try to switch to (play with?) IntelliJ IDEA 9 (so I am a newbie in this environment) and I've noticed that additional source directory is not added during IDEA's importing process...最近我尝试切换到(玩?)IntelliJ IDEA 9(所以我是这个环境中的新手)并且我注意到在IDEA的导入过程中没有添加额外的源目录......

Is there any way I can configure IDEA/Maven to make importing directory with generated source code automatically?有什么方法可以配置 IDEA/Maven 以自动使用生成的源代码导入目录?

The convention with Maven is to generate code in target/generated-sources/<tool> , for example target/generated-sources/jaxb2 Maven 的约定是在target/generated-sources/<tool>生成代码,例如target/generated-sources/jaxb2

Follow this convention and IDEA will add the folder as source folder (see IDEA-53198 ).遵循此约定,IDEA 会将文件夹添加为源文件夹(请参阅IDEA-53198 )。

Generated code, using jaxb2-maven-plugin, was missing for me in Intellij 2017.1 whereas Eclipse Neon created it.我在 Intellij 2017.1 中缺少使用 jaxb2-maven-plugin 生成的代码,而 Eclipse Neon 创建了它。 Fixed it from context menu of module by selecting 'Maven -> Generate Sources and Update Folders'.通过选择“Maven -> 生成源和更新文件夹”从模块的上下文菜单中修复它。

Try with maven-jaxb2-plugin .尝试使用maven-jaxb2-plugin If it does not work then it's IDEA problem.如果它不起作用,则是IDEA问题。

In Maven you can add new source roots per configuration.在 Maven 中,您可以为每个配置添加新的源根。 Maven plugins can do this programmatically. Maven 插件可以以编程方式执行此操作。 This is for sure the case with maven-jaxb2-plugin .这肯定是maven-jaxb2-plugin Then, if IDEA does not recognize it, then it's a problem on that side.然后,如果 IDEA 不识别它,那么它是那一侧的问题。

You can use the Maven Build Helper Plugin.您可以使用 Maven 构建助手插件。 It is located at http://www.mojohaus.org/build-helper-maven-plugin/它位于http://www.mojohaus.org/build-helper-maven-plugin/

It allows to configure additional source roots.它允许配置额外的源根。 And the maven integration of IntelliJ will add the new source root.并且 IntelliJ 的 maven 集成将添加新的源根。 We are using this feature in quite a few builds and it works just fine.我们在相当多的构建中使用了这个功能,它工作得很好。 Tested with vers.用版本测试。 13 of IntelliJ IDEA. IntelliJ IDEA 的第 13 条。

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

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