#How to get the project path in java?
How to get the project path in java:
1. The project path refers to the root path of the classpath.
Is the starting point for finding configuration files and classloader loading bytecode
This time I will take IntelliJ IDEA as an example to talk about the project path, that is, classpath
Shared before There is an article about the difference between classpath and path. If you are interested, you can check it out
2. Use Java API to view.
Code: public class ClassPathDemo { public static void main(String[] args) { String classPath = ClassPathDemo.class.getResource("/").getPath(); System.out.println("项目路径:" + classPath); } }
3. Execute the above code and see the printed information
Output:
Project path:/E: /java/JavaStudy/out/production/JavaStudy/
4. In the process of using IDEA, it is troublesome to check the project path through the API to find the compiled class. .
This can be found in the IDEA configuration.
Let’s share how to check the project path in the IDEA configuration, that is, find the classpath of the execution code
Right-click in the Project panel and select "Open Module Settings" in the pop-up menu
5. In the pop-up "Project Structure" dialog box, select the "Paths" Tab option Card
In the Compiler output, the default selection is "Inherit project compile output path"
That is, the current module uses the Compiler output path of the Project.
So where is the Compiler output path of Project?
6. Click the "Project" option on the left, and you can see the Project's compiler output in the right window.
Is this path consistent with the JAVA API? The inputs are basically the same.
“This directory contains tow subdirectories:Production and Test for production code and test sources,respectively.”
Recommended tutorial: "JAVA Video Tutorial"
The above is the detailed content of How to get the project path in java?. For more information, please follow other related articles on the PHP Chinese website!