将Maven项目导入Eclipse并修复错误

Per*_*ril 13 java eclipse maven-3 maven

我把一个项目导入了eclipse,每个类名都有很多错误,甚至像String这样的类......

我所做的课程中的错误是 Implicit super constructor Object() is undefined for default constructor. Must define an explicit constructor

在方法内部<Class> cannot be resolved to a type 甚至IOException我得到了IOException cannot be resolved to a type

所以我该怎么做 ?我试着建造,再次清洁没有用

更新:我也得到了描述

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
Run Code Online (Sandbox Code Playgroud)

Sin*_*ski 18

您导入的项目是Maven项目.你应该做的是打开位于项目根目录中的pom.xml文件,并在文件的插件管理部分添加以下插件:

<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>
Run Code Online (Sandbox Code Playgroud)

然后右键单击该项目,转到Maven并更新项目配置.

这应该解决它.


Rat*_*tha 3

您是否能够成功构建项目..如果是这样,请不要导入它..再次运行@项目根级别;

#mvn eclipse:eclipse -o  
Run Code Online (Sandbox Code Playgroud)

这将创建一个 Eclipse 项目。然后“导入为现有项目”。所有类路径问题都将得到解决。但是您需要将 .m2 home 设置为构建路径中的变量。