Problems by import of a multiple modules maven 2 project into eclipse workspace

孤街醉人 提交于 2019-12-05 18:58:25

As documented in the Why generated source folders are not added to classpath entry of the FAQ:

Maven plugins used to generate source code from resources or other sources can register additional source folders to Maven project during the build. Usually such plugins are bound to process-resources (or process-test-resources) build phase (for example jaxb, modello or xdoclet plugins). This means that to get those source folders for generated sources, we have to run corresponding Maven build phase.

Not all projects using generated sources, so for performance reasons, m2eclipse does not run any Maven goals by default on project import. This can be changed in the Maven settings in "Window > Preferences... > Maven > Goals to run on project import" (e.g. you can specify "process-resources" build phase or specific plugins in that field).

Alternatively you can run "Maven > Update project configuration" action from the project popup menu, which is configured to run "process-resources" by default and it can be also changed on the same preference page.

So either add the goal to which the source generation process is bound to the list of goals to run on import or generate sources by running maven and update the project configuration.

Karan

Try using mvn eclipse:eclipse

Under the project where you have additionally generated source. When this is generated by maven it is normally under target folder.

Therefor eclipse:eclipse will recognize this and add as a source folder.

Rembember to refresh the project after this.

Use build-helper-maven-plugin (sample bellow) to tell Eclipse to add a generated folder to the build path :

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>target/generated-sources/cxf</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

Add this in the pom of each project that generates sources...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!