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

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

How to create a src/main/resources directory?

javaeclipse

提问by Kunal Batra

All my classes were working fine. Then I wanted to create main/resourcesto add logback.xmlin main/resourcesin my project

我所有的课程都运行良好。然后我想创建main/resourceslogback.xmlmain/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

但是在创建文件夹后,我在所有类中都出现错误,并且主文件夹被转换为包

directory structure

目录结构

How can I add the folder main/resources in my src folder?

如何在我的 src 文件夹中添加文件夹 main/resources?

Or is there any way to add logback.xmlin any package in spring MVC?

或者有什么方法可以logback.xml在spring MVC中添加任何包?

采纳答案by Jad Chahine

To add a resource folder in eclipse:

在 Eclipse 中添加资源文件夹:

  • Click on Build Path

  • 点击 Build Path

  • Click on Configure Build Path

    (or Properties-> Java Build Path)

  • 点击 Configure Build Path

    (或Properties-> Java Build Path

  • Click on Source Tab

    enter image description here

    Click on Add Folder

    enter image description here

  • 点击 Source Tab

    在此处输入图片说明

    点击 Add Folder

    在此处输入图片说明

  • Click on 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.xmlin src folder it ll work.

    只有 Maven 项目会在 src 中自动生成资源文件夹,其他解决方案将放在logbackback.xmlsrc 文件夹中它会起作用。

    回答by soufrk

    Locate your pom.xml. Navigate to the buildtag in it. Inside this tag you will have to look for any declaration regarding your source directory. Might be sourceDirectorydireclty, or it might appear in any of pluginas 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

    Right Click your project -> Build Path -> New Source Folder

    右键单击您的项目 -> 构建路径 -> 新建源文件夹

    Type the folder path, src/main/resources and click Finish.

    输入文件夹路径 src/main/resources 并单击完成。

    Screenshots below.

    截图如下。

    Step 1: Figure: 1

    第 1 步:图:1

    Step 2: Figure: 2

    第 2 步:图:2

    回答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

    * image 1

    * 图 1

    image 2

    图 2

    image 3

    图 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 taband then click on add folderand browse the resources folderand add that's all. See below image for more description and help. image 4

    现在在最后一步,将新添加的资源文件夹添加到构建路径中。通过单击属性或直接构建路径按钮。 Click on source tab然后click on add folderbrowse the resources folder并添加这就是全部。有关更多说明和帮助,请参见下图。 图 4