在 Eclipse 提供的默认 Maven 目录结构中创建文件夹会导致任何问题吗?

huangapple go评论83阅读模式
英文:

Does creating a folder in default maven directory structure offered by eclipse lead to any issues?

问题

我最近开始学习Spring REST。作为学习过程的一部分,我使用Maven开发了一个简单的Hello World应用程序。由Eclipse提供的Maven目录结构中不包含“java”文件夹。因此,我明确地添加了它。正如您在下面的图片中所见,该应用程序给我返回了404错误。我确信这与类路径有关。由于我刚接触Maven,我不太理解类路径的概念。

但在第二张图片中,我使用了“co.ntier”(用于Spring MVC的Maven原型)。这个原型的目录结构包含了java文件夹,所以当我运行应用程序时,能够得到输出。

如何添加或配置Maven,以便每次创建新的Maven项目时,目录结构都包含java文件夹?请帮助我。

英文:

I've recently started learning Spring REST. As part of my learning process, I developed a simple Hello World application using Maven. The directory structure of maven offered by Eclipse doesn't contain the "
java" folder in src/main. So, I added it explicitly. It turns out the application gives me a 404 error as you can see in the below image. I'm sure this has something to do with the class path. As I'm new to maven I don't understand the concept of the classpath.

But in the second image, I created the project using "co.ntier" (maven archetype for Spring MVC). The directory structure of this archetype has got the java folder which is why when I run the application I'm able to get the output.
How to add or configure maven so that every time I create a new maven project, the directory structure will have the java folder? Please help me.在 Eclipse 提供的默认 Maven 目录结构中创建文件夹会导致任何问题吗?

在 Eclipse 提供的默认 Maven 目录结构中创建文件夹会导致任何问题吗?

答案1

得分: 1

我建议始终从原型创建一个Maven项目。

你可以例如使用快速启动原型来创建一个简单的项目。

英文:

I recommend to always create a Maven project from an archetype.

You can e.g. use the quickstart archetype for a simple project.

答案2

得分: 1

一个名为“java”的文件夹是否存在与一个应用程序能否成功地在特定网址上提供内容无关。它们没有直接关联。这与类路径也没有关系。

然而,项目上的红色标记表示存在错误,并且在Maven项目中,可编译源代码的默认位置是“src/main/java”,因此可以清楚地看出缺少“java”文件夹会导致项目未部署,这就是为什么会出现404错误。

简而言之,如果项目中有红色标记,它将无法部署。

英文:

The presence of a "java" folder has nothing to do with whether an application can successfully serve something at a particular url. They are not directly related. This also has nothing to do with the classpath.

However, the red mark on the project indicates an error, and as the DEFAULT location for compilable source in a Maven project is "src/main/java", it seems clear that the lack of the "java" folder results in the project not being deployed, which IS why you get a 404.

In short, if you have red marks in the project, it's not going to deploy.

huangapple
  • 本文由 发表于 2020年9月24日 19:45:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/64045745.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定