Java Get Project Catalog

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.