Java 如何创建 src/main/resources 目录?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36907204/
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
How to create a src/main/resources directory?
提问by Kunal Batra
All my classes were working fine. Then I wanted to create main/resources
to add logback.xml
in main/resources
in my project
我所有的课程都运行良好。然后我想创建main/resources
加logback.xml
在main/resources
我的项目
I got help from "How to create main/java inside src"
我从“如何在 src 中创建 main/java”获得帮助
But after creating the folders I am getting errors in all my classes, and the main folders were converted into packages
但是在创建文件夹后,我在所有类中都出现错误,并且主文件夹被转换为包
How can I add the folder main/resources in my src folder?
如何在我的 src 文件夹中添加文件夹 main/resources?
Or is there any way to add logback.xml
in any package in spring MVC?
或者有什么方法可以logback.xml
在spring MVC中添加任何包?
采纳答案by Jad Chahine
To add a resource folder in eclipse:
在 Eclipse 中添加资源文件夹:
Build Path
Build Path
Configure Build Path
(or Properties
-> Java Build Path
)
Configure Build Path
(或Properties
-> Java Build Path
)
Source Tab
Click on Add Folder
Source Tab
点击 Add Folder
Create new Folder
Create new Folder
回答by Roxana Roman
Try to add new Source Folder. Right click on your src->New>Source Folder:main/resources
尝试添加新的源文件夹。右键单击您的 src->New>Source Folder:main/resources
回答by Nazaret K.
Since you're not using Maven, you shouldn't be creating the src/main/resources folder. Just put logback.xml in the src folder.
由于您没有使用 Maven,您不应该创建 src/main/resources 文件夹。只需将 logback.xml 放在 src 文件夹中。
Also move your java files (with their entire package folder structure) back to src as they were before creating the main/resources.
还要将您的 java 文件(及其整个包文件夹结构)移回 src,就像在创建 main/resources 之前一样。
回答by Ray Q
maybe you could created the new folder.Then,opening this object's properties and clicking 'Java Build Path'.Reelecting the source folder on build path.Just try,man!
也许您可以创建新文件夹。然后,打开此对象的属性并单击“Java 构建路径”。在构建路径上重新选择源文件夹。试试吧,伙计!
回答by KhAn SaAb
Only maven project automatically generate resource folder inside src, other solution would be put logbackback.xml
in src folder it ll work.
只有 Maven 项目会在 src 中自动生成资源文件夹,其他解决方案将放在logbackback.xml
src 文件夹中它会起作用。
回答by soufrk
Locate your pom.xml
. Navigate to the build
tag in it. Inside this tag you will have to look for any declaration regarding your source directory. Might be sourceDirectory
direclty, or it might appear in any of plugin
as well. Upon finding so, try un-commenting the same and do a Right Click->Maven->Update Project. Should solve for most cases. If not you have some other issue.
找到您的pom.xml
. 导航到其中的build
标签。在此标签中,您必须查找有关源目录的任何声明。可能是sourceDirectory
直接的,也可能出现在任何一个plugin
中。找到后,尝试取消注释并执行Right Click->Maven->Update Project。大多数情况下应该可以解决。如果没有,您还有其他问题。
回答by Daniel Raja
回答by JavaSheriff
If your project is eclipse project then it will automatically recognize the folders
Open command line, change directory to the folder with the pom.xml
and past this into the CMD:
如果您的项目是 eclipse 项目,那么它会自动识别文件夹
打开命令行,将目录更改为 pom.xml 的文件夹并将其传递
到 CMD 中:
echo This will create all required folders for maven project.
echo creating Application\Library sources
MD "src\main\java"
echo creating Application\Library resources
MD "src\main\resources"
echo creating Resource filter files
MD "src\main\filters"
echo creating Web application sources
MD "src\main\webapp"
echo creating Test sources
MD "src\test\java"
echo creating Test resources
MD "src\test\resources"
echo creating Test resource filter files
MD "src\test\filters"
echo creating Integration Tests (primarily for plugins)
MD "src\it"
echo creating Assembly descriptors
MD "src\assembly"
echo creating Site
MD "src\site"
回答by Mukesh Kumar Gupta
The same problem I also encountered while I was learning the spring boot wanted to add logback.xml in resources.
I am using sts for spring boot. As of my understanding, there are two things your file system folder structure and another sts folder structure.
First I created a folder in your file system at src/main/
and then add this folder into build path. *
我在学习spring boot时也遇到了同样的问题,想在资源中添加logback.xml。我正在使用 sts 作为弹簧靴。据我了解,您的文件系统文件夹结构和另一个 sts 文件夹结构有两件事。首先,我在您的文件系统中创建了一个文件夹,src/main/
然后将此文件夹添加到构建路径中。*
For creating a folder follow below image 1,2 and 3
要创建文件夹,请按照下图 1,2 和 3
Now at the final step, add newly added resource folder into the build path. by clicking properties or directly build path button.
Click on source tab
and then click on add folder
and browse the resources folder
and add that's all. See below image for more description and help.
现在在最后一步,将新添加的资源文件夹添加到构建路径中。通过单击属性或直接构建路径按钮。
Click on source tab
然后click on add folder
和browse the resources folder
并添加这就是全部。有关更多说明和帮助,请参见下图。