且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Eclipse中将简单的Java项目转换为Maven项目后出现NoClassDefFoundError

更新时间:2023-11-17 23:39:34

项目目录结构与默认的Maven目录结构不匹配. Maven希望源位于根文件夹(包含pom.xml的文件夹)下的src/main/java目录中.来源在src文件夹中,因此出现No sources to compile错误.

The project directory structure does not match with the default Maven directory structure. Maven expects the source to be in src/main/java directory under the root folder (the folder containing pom.xml). The source here is in the src folder hence the No sources to compile error.

您可以移动源以使用默认的Maven目录结构,也可以通过将以下内容添加到pom的build部分中来更改pom.xml以显式指定源目录:

You can either move your sources to use the default Maven directory structure or change the pom.xml to explicitly specify your source directory by adding the following to the build section of the pom:

<sourceDirectory>${basedir}/src</sourceDirectory>

有关Maven标准目录布局的更多信息,请参见

More info on Maven's standard directory layouts can be found here.