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

问题描述:

在我们的项目中,我们使用 jaxb2-maven-plugin 从 XML Schema 生成 Java 源代码,这导致我们的 Maven 模块需要额外的源代码目录(在我们的例子中是 target/生成/主/java).到目前为止,我一直在使用 Eclipse 和 maven-eclipse-plugin 将所有项目导入 Eclipse 工作区.该插件(以某种方式)能够将带有生成的源代码的目录自动添加到 Eclipse 的 .classpath 文件中.

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). Up to date I've been using Eclipse and maven-eclipse-plugin to import all the projects into Eclipse workspace. The plugin is (somehow) able to add the directory with generated source code automatically to Eclipse' .classpath file.

最近我尝试切换到(玩?)IntelliJ IDEA 9(所以我是这个环境的新手)并且我注意到在IDEA的导入过程中没有添加额外的源目录......

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...

有什么办法可以配置 IDEA/Maven 来自动导入带有生成的源代码的目录吗?

Is there any way I can configure IDEA/Maven to make importing directory with generated source code automatically?

与Maven的约定是在target/generated-sources/中生成代码,例如target/generated-sources/jaxb2

The convention with Maven is to generate code in target/generated-sources/<tool>, for example target/generated-sources/jaxb2

遵循此约定,IDEA 会将文件夹添加为源文件夹(请参阅 IDEA-53198).

Follow this convention and IDEA will add the folder as source folder (see IDEA-53198).