在没有 Maven 的情况下在 Eclipse 中创建 src/main/java 文件夹结构

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22914927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 18:56:59  来源:igfitidea点击:

Creating a src/main/java folder structure in Eclipse without Maven

javaeclipseweb-applications

提问by Sandeep Rao

How do I create the src/main/javaand src/test/javain my default web application project in Eclipse without Maven? My current folder structure is

如何在没有 Maven 的情况下在 Eclipse 中的默认 Web 应用程序项目中创建src/main/javasrc/test/java?我当前的文件夹结构是

TestApp
├── JavaResources
│   └── src  
│       └── com.mypackage
└── WebContent

采纳答案by Ian Roberts

As you've discovered, you can't have a source folder inside another source folder, so before you can create src/main/javayou have to tell Eclipse not to treat srcas a source folder. To do this, right click on the srcfolder and select build path -> remove from build path.

正如您所发现的,在另一个源文件夹中不能有源文件夹,因此在创建之前,src/main/java您必须告诉 Eclipse 不要将其src视为源文件夹。为此,请右键单击该src文件夹并选择构建路径 -> 从构建路径中删除。

Once you have done this srcwill appear in the folder tree in its normal place, so you can create the mainand javafolders under it, and move the existing src/comto src/main/java/com. Finally right-click the newly-created javafolder and select build path -> use as source folder.

完成后,这src将出现在文件夹树中的正常位置,因此您可以在其下创建mainjava文件夹,并将现有文件夹移动src/comsrc/main/java/com. 最后右键单击新创建的java文件夹并选择构建路径 -> 用作源文件夹。

回答by greg-449

Open Properties > Java Build Pathfor the project. Select the Sourcetab and use Add Foldersto add source folders.

Properties > Java Build Path为项目打开 。选择Source选项卡并用于Add Folders添加源文件夹。

回答by markusw

Remove the actual source folder definition in the build path and add a new source folder an name it src/main/java

删除构建路径中的实际源文件夹定义并添加一个新的源文件夹并为其命名 src/main/java

回答by Dunco

I have solved this issue by below steps:

我已经通过以下步骤解决了这个问题:

Right click the Maven Project -> Build Path -> Configure Build Path In Order and Export tab, you can see the message like '2 build path entries are missing' Now select 'JRE System Library' and 'Maven Dependencies' checkbox Click OK

右键单击 Maven 项目 -> 构建路径 -> 按顺序配置构建路径和导出选项卡,您可以看到类似“缺少 2 个构建路径条目”的消息现在选择“JRE 系统库”和“Maven 依赖项”复选框单击确定

回答by AmosJ

the problem will be solved by checking on 'JRE System Library' and 'Maven Dependencies' checkboxs Click OK. this is found in the project's 'build path option'

该问题将通过选中“JRE 系统库”和“Maven 依赖项”复选框来解决。单击“确定”。这可以在项目的“构建路径选项”中找到

回答by kiran kumar

enter image description here

在此处输入图片说明

If you don't find the Included Path just add the path it will resolve.

如果您没有找到包含路径,只需添加它将解析的路径。

回答by Puneet Lamba

If the package structure is setup as src.main.java.com.inventica, instead of com.inventica, that's usually because under project properties > Java build path > Source, the source folder is setup as “src” instead of “src/main/java”. There's no easy way to fix this, so remove “src” as a source folder and click ok. Now eclipse will show a folder hierarchy “src/main/java”. Browse to the “java” folder > right click > build path > use as source folder. After this you may have to fix the Eclipse .project and .classpath files to have it use Maven to manage dependencies, builds etc. Typically, you can copy this from a working project since there isn't anything project specific here assuming you're structured as a standard Maven project.

如果包结构设置为 src.main.java.com.inventica,而不是 com.inventica,那通常是因为在项目属性 > Java 构建路径 > 源下,源文件夹设置为“src”而不是“src/主/java”。没有简单的方法来解决这个问题,所以删除“src”作为源文件夹,然后单击“确定”。现在 eclipse 将显示一个文件夹层次结构“src/main/java”。浏览到“java”文件夹>右键单击>构建路径>用作源文件夹。在此之后,您可能必须修复 Eclipse .project 和 .classpath 文件,使其使用 Maven 来管理依赖项、构建等。通常,您可以从工作项目中复制它,因为这里没有任何特定于项目的假设您是构建为标准的 Maven 项目。

回答by Guru

Simple solution would be create 'java' folder directly one the drive into src/main even before opening it in eclipse that way eclipse will not complain about the issue.

简单的解决方案是直接将“java”文件夹创建到 src/main 中,即使在 eclipse 中打开它之前,eclipse 也不会抱怨这个问题。