在没有 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
Creating a src/main/java folder structure in Eclipse without Maven
提问by Sandeep Rao
How do I create the src/main/java
and src/test/java
in my default web application project in Eclipse without Maven? My current folder structure is
如何在没有 Maven 的情况下在 Eclipse 中的默认 Web 应用程序项目中创建src/main/java
和src/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/java
you have to tell Eclipse not to treat src
as a source folder. To do this, right click on the src
folder and select build path -> remove from build path.
正如您所发现的,在另一个源文件夹中不能有源文件夹,因此在创建之前,src/main/java
您必须告诉 Eclipse 不要将其src
视为源文件夹。为此,请右键单击该src
文件夹并选择构建路径 -> 从构建路径中删除。
Once you have done this src
will appear in the folder tree in its normal place, so you can create the main
and java
folders under it, and move the existing src/com
to src/main/java/com
. Finally right-click the newly-created java
folder and select build path -> use as source folder.
完成后,这src
将出现在文件夹树中的正常位置,因此您可以在其下创建main
和java
文件夹,并将现有文件夹移动src/com
到src/main/java/com
. 最后右键单击新创建的java
文件夹并选择构建路径 -> 用作源文件夹。
回答by greg-449
Open Properties > Java Build Path
for the project. Select the Source
tab and use Add Folders
to 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
回答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 也不会抱怨这个问题。