Import Maven Project to Eclipse and Fix the errors

a 夏天 提交于 2021-02-07 11:31:33

问题


I made imported a project to eclipse and I have a lot of errors in every class name even classes like String ...

the error in the classes I made is Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor

and inside the methods <Class> cannot be resolved to a type even to IOException I am getting IOException cannot be resolved to a type

so what should I do ? I tried to build , clean again with no use

UPDATE : also I am getting Description

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-resources-plugin:2.4.3:resources (execution: default-resources, phase: process-resources)   pom.xml /test line 6    Maven Project Build Lifecycle Mapping Problem

回答1:


The project that you imported is a Maven project. What you should do is open the pom.xml file located in the root of the project and add the following plugin in the plugin management part of the file:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-resources-plugin</artifactId>
                                    <versionRange>[2.0,)</versionRange>
                                    <goals>
                                        <goal>resources</goal>
                                        <goal>testResources</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

Then right click the project, go to Maven and Update project configuration.

This should fix it.




回答2:


I think that your problem is not in maven project and not in import procedure but in your eclipse configuration. It seems that your eclipse "does not see" correct JDK.

So, first try to create the simple "hello world" project and see if it works. When this works import your maven project again, i.e. run command mvn eclipse:eclipse and then open the project using eclipse. If this is your first eclipse project you have to create M2_REPO variable that will refer to your maven repository (USER_HOME/.m2/repository)

If you still have problems try to refresh and clean the project.

If the problem still happens compare which JDK are you using in "good" and "bad" project. I believe that you will see difference there. So, fix it.




回答3:


Were you able to build the project successfully.. If so, don't import it..again run @ project root level;

#mvn eclipse:eclipse -o  

This will create a eclipse project.Then 'import as existing project.' All classpath problem will get solved..But you need to set your .m2 home as a variable in your build path..




回答4:


Go to Project->Properties->Java build path->Libraries. Is the JRE System Library added? Does it point to the correct location?

Also try running mvn eclipse:eclipse on the root folder of the project (You will need to download maven and add it to the classpath first).



来源:https://stackoverflow.com/questions/7638562/import-maven-project-to-eclipse-and-fix-the-errors

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