java--classpath

classpath is the class of the path, that is, class files (* .class path). Speaking a path to the file, we need to understand a great java project (usually web project) that runs in real time, this internal project directory structure of the file; so, we go to analyze, understand classpath. And we often use classpath place, that is, specify a number of configuration / resources will be used to document the time. For example, we specify in web.xml springmvc profile, we use: classpath:entry/dev/spring-mvc.xml; another example, when we put * Mapper.xml file in the main/java/../mapping/next folder, and configure its position in mybatis profile, we use :classpath*:**/mapper/mapping/*Mapper.xml

Obviously, these two above classpath configuration, is to tell the configuration file, we want to specify where to find the configuration file. To figure out why this is written above, we have to look at (or after release) when the project runs a directory structure.

After the release of the web project directory structure

We used to package IDEA project, one is the war package, one is the explorer folder, unpack the war is the explorer. Let's directory structure decompressed for analysis.

 

For comparison, we have to note that the project development period, the src/main/following javaand resourcesfolders are (compiled) package to produce the package WEB-INF/classes/directory; while the original WEB-INF web.xml and the following views are still yet WEB- INF below. At the same time introduced by the dependent maven are put into the WEB-INF/lib/following. Finally, class and resource files compiled classes are placed under the directory.

 

This is the original classpath

In the project compiled package, the root directory META-INFand WEB-INF . This time, we can see this folder classes, which is what we are looking for classpath.

在第1个例子里,classpath:entry/dev/spring-mvc.xml 中,classpath就是指WEB-INF/classes/这个目录的路径。需要声明的一点是,使用classpath:这种前缀,就只能代表一个文件

在第2个例子里,classpath*:**/mapper/mapping/*Mapper.xml,使用classpath*:这种前缀,则可以代表多个匹配的文件**/mapper/mapping/*Mapper.xml,双星号**表示在任意目录下,也就是说在WEB-INF/classes/下任意层的目录,只要符合后面的文件路径,都会被作为资源文件找到。

Guess you like

Origin www.cnblogs.com/jvStarBlog/p/11287954.html