Solve the problem that resource files such as xml under src in IDEA cannot be read

The essence of the problem is that idea's regulations on classpath. In eclipse, the resource file can be found by placing it in the src folder; but in idea, the resource file can be directly placed in the src folder, if it is not set, it cannot be found. Here are a few solutions, which are very confusing on the Internet. I will make a summary here: Recommended method 41. Putting all resource files in the resources folder is very convenient and easy to think of, but the hierarchy is very poor. For example, the mapping configuration file mapper.xml of mybatis needs to be placed in a specific package, which is the same level as the dao layer, the service layer, etc., but now it can only be placed under the resource folder, which is not convenient for layering; 2 .If the project is a maven project: configure the pom file configuration of maven, find the node in the pom file, add the following code: [html] view plain copy src/main/java **/*.xml I have tried modifying the directory to The specific package for placing the configuration file is modified to src/main/java/lj/ncepu/mapperXML, and then a lot of modifications and attempts have been made in the label, but the configuration file cannot be accessed; therefore, using the above configuration directly Good; if you still can't access, welcome to the thread to discuss; if you know how to modify it, please also thread to discuss, thank you~ Reference: Compile the xml and other resource files under the src source code in the IDEA maven project into the classes folder 3 .The package containing the configuration file, mark directory as ... Resources: directly right-click on the package -> Mark Directory As, you will find that there is only one exclude; what to do? Project Structure -> Modules -> Sources -> select the package containing the configuration file -> Mark as -> select the third Resources -> OK Reference: http://stackoverflow.com/questions/6104551/java-setting-classpath4. Add the package to the classpath: Project Struture -> Modules -> Dependencies -> "+" -> JARS or directories -> select the package -> pop up Choose Categories of Selected Files -> select Classes -> OK Reference: http:// stackoverflow.com/questions/854264/how-to-add-directory-to-classpath-in-an-application-run-profile-in-intellij-idea The above methods are to find resource files in the IDEA development environment, However, whether the specific package release will include the resource file still needs to be tested. My test result is that all 4 methods can include the xml file in the package when publishing.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326564418&siteId=291194637