Home > Backend Development > XML/RSS Tutorial > How to solve the problem that resource files such as xml under src cannot be read in IDEA

How to solve the problem that resource files such as xml under src cannot be read in IDEA

黄舟
Release: 2017-05-07 13:44:15
Original
2709 people have browsed it

The essence of the problem is the idea's regulations on classpath.

In eclipse, you can find the resource files by placing them in the src folder;

But in idea, you can directly place the resource files in the src folder. If you do not proceed Settings cannot be found.

Let’s talk about several solutions. Everything on the Internet is very confusing. Let me make a summary here: Recommended method 4

1. Place all resource files in the resources folder

This is very convenient and easier to think of, but the hierarchy is very poor. For example, the mapping configuration file mapper.xml of mybatis originally needs to be placed in a specific package, along with the dao layer, service layer, etc. The levels are at the same level. Now they can only be placed under the resource folder, which is inconvenient to layer;

2. If the project is a maven project:

Configure the maven pom file configuration, in Find the node in the pom file and add the following code:

<build>  
    <resources>  
        <resource>  
            <directory>src/main/java</directory>  
            <includes>  
                <include>**/*.xml</include>  
            </includes>  
        </resource>  
    </resources>  
</build>
Copy after login

I have tried changing the directory to a specific package where the configuration file is placed, that is, to src/main/java/lj/necpu/mapperXML , and then a lot of modifications and attempts were made in the tag, but the configuration file was still unable to be accessed;

So, just use the configuration above; if you still cannot access, welcome to discuss; If you know how to modify it, please also discuss it in the thread, thank you~

3. Mark directory as... Resources:

right-click the package containing the configuration file. Click on the package-> Mark Directory As, you will find that there is only one exclude; what should I do?

Project Structure -> Modules -> Sources -> Select the package containing the configuration file -> Mark as -> Select the third Resources -> OK

4. Add package to classpath:

Project Struture -> Modules -> Dependencies -> "+" -> JARS or directories -> Select package

-> Pop-up Choose Categories of Selected Files -> Select Classes -> OK

The above methods can find resource files in the IDEA development environment, but whether the specific package and release will include the resource files requires specific testing.

My test result is that all 4 methods can include the xml file in the package when publishing.

The above is the detailed content of How to solve the problem that resource files such as xml under src cannot be read in IDEA. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template