[英]How to create a src/main/resources directory?
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?或者有什么方法可以在spring MVC的任何包中添加
logback.xml
?
To add a resource folder in eclipse:在 Eclipse 中添加资源文件夹:
Build Path
Build Path
Configure Build Path
Configure Build Path
(or Properties
-> Java Build Path
) (或
Properties
-> Java Build Path
)
Source Tab
Source Tab
Click on Add Folder
点击
Add Folder
Create new Folder
Create new Folder
The same problem I also encountered while I was learning the spring boot wanted to add logback.xml in resources.我在学习spring boot时也遇到了同样的问题,想在资源中添加logback.xml。 I am using sts for spring boot.
我正在使用 sts 作为弹簧靴。 As of my understanding, there are two things your file system folder structure and another sts folder structure.
据我了解,您的文件系统文件夹结构和另一个 sts 文件夹结构有两件事。 First I created a folder in your file system at
src/main/
and then add this folder into build path.首先,我在
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. Click on source tab
,然后click on add folder
并browse the resources folder
并添加这一切。 See below image for more description and help.有关更多说明和帮助,请参见下图。
Try to add new Source Folder.尝试添加新的源文件夹。 Right click on your src->New>Source Folder:main/resources
右键单击您的 src->New>Source Folder:main/resources
右键单击您的项目 -> 构建路径 -> 新建源文件夹并键入您要创建的资源文件夹的名称,例如 ----->src/main/resources 或 src/test/resources ..它将创建一个新建资源文件夹
Since you're not using Maven, you shouldn't be creating the src/main/resources folder.由于您没有使用 Maven,您不应该创建 src/main/resources 文件夹。 Just put logback.xml in the src folder.
只需将 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 之前一样。
只有 maven 项目会在 src 中自动生成资源文件夹,其他解决方案将logbackback.xml
放在 src 文件夹中就可以了。
Locate your pom.xml
.找到您的
pom.xml
。 Navigate to the build
tag in it.导航到其中的
build
标记。 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.可能是
sourceDirectory
direclty,也可能出现在任何plugin
中。 Upon finding so, try un-commenting the same and do a Right Click->Maven->Update Project .找到后,尝试取消注释并执行Right Click->Maven->Update Project 。 Should solve for most cases.
大多数情况下应该可以解决。 If not you have some other issue.
如果没有,您还有其他问题。
也许您可以创建新文件夹。然后,打开此对象的属性并单击“Java 构建路径”。在构建路径上重新选择源文件夹。试试吧,伙计!
If your project is eclipse project then it will automatically recognize the folders如果你的项目是eclipse项目,那么它会自动识别文件夹
Open command line, change directory to the folder with the pom.xml打开命令行,将目录更改为 pom.xml 所在的文件夹
and past this into the CMD:并将其传递到 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"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.