How to configure IntelliJ IDEA and/or Maven to automatically add directories with Java source code generated using jaxb2-maven-plugin?
Solution 1
The convention with Maven is to generate code in target/generated-sources/<tool>
, for example target/generated-sources/jaxb2
Follow this convention and IDEA will add the folder as source folder (see IDEA-53198).
Solution 2
Generated code, using jaxb2-maven-plugin, was missing for me in Intellij 2017.1 whereas Eclipse Neon created it. Fixed it from context menu of module by selecting 'Maven -> Generate Sources and Update Folders'.
Solution 3
Try with maven-jaxb2-plugin. If it does not work then it's IDEA problem.
In Maven you can add new source roots per configuration. Maven plugins can do this programmatically. This is for sure the case with maven-jaxb2-plugin
. Then, if IDEA does not recognize it, then it's a problem on that side.
kopper
Updated on July 09, 2022Comments
-
kopper almost 2 years
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 casetarget/generated/main/java
). Up to date I've been using Eclipse andmaven-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.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...
Is there any way I can configure IDEA/Maven to make importing directory with generated source code automatically?
-
dmatej almost 11 yearsBut what if we need to set custom value? What if the directory is used also with another tool doing another phase? At this time, with Eclipse we don't have a problem, but with IDEA we do.
-
ᄂ ᄀ almost 10 years@dmatej It is possible to set the location for generated sources. See 'Generated sources folders' option at jetbrains.com/idea/webhelp/maven-importing.html
-
Robert Massaioli almost 8 yearsBe sure to use mvn idea:idea to ensure that this takes place after adding the mvn plugin module to your pom.
-
mmdemirbas almost 6 years
mvn idea:idea
solved the issue in my case. Thank you.