Background: When the program executes, it involves going to read the configuration file and so on, you need to know how to get the file path Java Directory mapping relationshipsNote: When Java code executes, information such as the compiled generated classes file and configuration files are generated to the target directory. The final executed file is actually the class file under TargetFor example:Project name: Zzappqaproject directory:/opt/script/zzappqatarget directory generated: Target The following is a mapping of a project file to the generated target directoryZZAPPQA project under the target file under the source code Java file classes under the class file resource file resourcesclasses under the Web site resource file Webappzzappqa (project name)
Documents under the ZZAPPQA project |
The file under target |
source Java files |
class file under Classes |
Resource Files Resources |
Classes under |
Resource file WebApp for Web site |
ZZAPPQA (project name)
|
general configuration files are placed in resource files under the resources of the comprehensive relationship, if you want to get the configuration file. Just find the classes directory under target. how to get the classes directory address:This.getclass (). GetResource ("/"). GetPath () How to get the project catalogDescription: The System.getproperty ("User.dir") is inconsistent on the Web site, both locally and when Tomcat is started
Method |
Description |
System.getproperty ("User.dir") |
1, if it is executed locally, get the project root directory 2. If booting in Tomcat, get the Tomcat bin directory |
Thread.CurrentThread (). Getcontextclassloader (). GetResource (""). ToString ()) |
get the classes root directory where Java compiled files are stored resource files Resources are also in this directory |
This.class.getClassLoader (). GetResource (""). GetPath () |
Ibid . get the classes root directory where Java compiled files are stored resource files Resources are also in this directory |
This.class.getClass (). GetResource ("/"). GetPath () |
Ibid . get the classes root directory where Java compiled files are stored resource files Resources are also in this directory |
This.class. GetClass (). getClassLoader (). GetResource ("."). GetPath () |
Ibid . get the classes root directory where Java compiled files are stored resource files Resources are also in this directory |
This.class.getClass (). GetResource ("/comm"). GetPath () |
get the Comm path under the classes directory Note: If the path does not exist, it will throw a null pointer exception |
System.getproperty ("Java.class.path") |
Get Java all class load path |
Java Get Project Catalog