简体   繁体   English

为什么我不能在Eclipse中新创建的maven webapp项目中使用New-> Source Folder?

[英]Why I can't use New->Source Folder in a new created maven webapp project in Eclipse?

I created a new maven webapp project in Eclipse, and there is src/main/resources folder and no src/main/java, so I right-clicked on the project folder and choose "New"->"Source Folder". 我在Eclipse中创建了一个新的maven webapp项目,并且有src / main / resources文件夹而没有src / main / java,所以我右键单击项目文件夹并选择“New” - >“Source Folder”。 When I type "src/main/java" I just get an error: 当我输入“src / main / java”时,我得到一个错误:

The folder is already a source folder. 该文件夹已是源文件夹。

and I found in my project's "Java Build Path" property there is a configuration of src/main/java 我在我的项目的“Java Build Path”属性中找到了src / main / java的配置 Java构建路径 why the project have this configuration while there is no such folder like src/main/java? 为什么项目有这个配置,而没有像src / main / java这样的文件夹?

Create the folder as an ordinary folder using New > Folder . 使用New > Folder将文件夹创建为普通文件New > Folder Eclipse will know it's a source folder when it's in a Maven project. Eclipse会在Maven项目中知道它是一个源文件夹。

This is a somewhat weird situation when Eclipse internally recognizes src/main/java as a source folder because Maven says it's a source folder even though the folder does not actually exist. 当Eclipse 内部src/main/java识别为源文件夹时,这有点奇怪,因为Maven说它是源文件夹,即使该文件夹实际上并不存在。 Because it does not exist, you won't see it listed as a source folder in project browser / package explorer - but you'll be given this error when you try to create it. 因为它不存在,所以您不会在项目浏览器/包浏览器中看到它被列为源文件夹 - 但是当您尝试创建它时,您将收到此错误。 In the moment you create the folder as an ordinary folder, Eclipse will realize this is the missing source folder and list it as such in GUI. 在您将文件夹创建为普通文件夹的那一刻,Eclipse将意识到这是缺少的源文件夹,并在GUI中将其列出。

I think you get the error because the folder does not exist. 我认为你得到错误,因为该文件夹不存在。 Just create the folder and then right click on the folder and select 只需创建文件夹,然后右键单击该文件夹并选择

Build Path -> Use as source folder

If that doesn't work just remove the folders that say "missing" and do the above procedure on the actual folders 如果这不起作用,只需删除说“丢失”的文件夹,然后对实际文件夹执行上述步骤

This is absurd, but following worked for me: 这很荒谬,但以下为我工作:

  • Create a normal folder: New -> Folder 创建一个普通文件夹:新建 - >文件夹
  • Delete that folder 删除该文件夹
  • Create new source folder: New -> Source Folder 创建新的源文件夹:新建 - >源文件夹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在创建新的maven项目时eclipse中的双源文件夹 - Double source folder in eclipse when creating new maven project 如何在Eclipse的new-> MyNewMenu上单击鼠标右键,添加弹出菜单? - how can I add popup menu in right-click new->MyNewMenu on eclipse? 如何在Eclipse中的File-> New-> Example ...中使新项目向导可见? - How to make new project wizard visible in File ->New->Example… in eclipse? 无法为 New->Servlet 选择项目 - Unable to select project for New->Servlet 为什么我不能在Eclipse中的现有Maven项目中创建Servlet - Why can't I create a Servlet in an existing Maven Project in Eclipse Test cases in new folder created parallel to src/test/java in latest Eclipse IDE maven java project is not executing the test cases - Test cases in new folder created parallel to src/test/java in latest Eclipse IDE maven java project is not executing the test cases 为什么我不能使用LinkedList :: new? - Why can't I use LinkedList::new? 无法在 Eclipse 中创建新的 EJB 项目 - Can't create new EJB project in eclipse 我创建了新的Java项目,但是Eclipse没有显示该项目 - i have created new Java Project, but Eclipse is not showing that project 我无法在 eclipse luna IDE 中创建新的 web 项目(找不到创建新的 web 项目) - I can't create a new web project in eclipse luna IDE (do not find create new web project)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM