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

梦想与她 提交于 2019-12-22 11:11:09

问题


I was wondering if someone has experienced the same problem as me and can help me. I have a maven project which contains 6 modules. Some of modules are depending on each other. The project is written in Java and builds to jars, wars and aar. I've been trying to import it to Eclipse with the m2eclipse plug-in. It seems to work fine until the project builds. During the build process I get hundreds of errors complaining about missing Java files which are generated. As I found out eclipse can't recognize that some of generated packages should be interpreted as source code. I don't realy know what to do with it as I spent a lot of time already trying to solve this issue. The project is building fine with command line. My target is to debug the whole project on Tomcat server that's why I want to use eclipse as it has a pretty good integration with Tomcat.

Every help would be greatly appreciated.

Thank you!


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/2421631/problems-by-import-of-a-multiple-modules-maven-2-project-into-eclipse-workspace

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