Home>Article>Java> How to get the project path in java?

How to get the project path in java?

coldplay.xixi
coldplay.xixi Original
2020-06-13 09:59:58 4718browse

How to get the project path in java?

#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

How to get the project path in java?

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); } }

How to get the project path in java?

3. Execute the above code and see the printed information

Output:

Project path:/E: /java/JavaStudy/out/production/JavaStudy/

How to get the project path in java?

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

How to get the project path in java?

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?

How to get the project path in java?

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.”

How to get the project path in java?

How to get the project path in java?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn