主页 > 经验 >
java中获取类加载路径和项目根路径的方法 java局域网获取项目路
java中获取类加载路径和项目根路径的方法 java局域网获取项目路径 Java中项目路径,就是classpath了。下面是小编跟大家分享的是java局域网获取项目路径,欢迎大家来阅读学习~
java局域网获取项目路径
工具/原料
java
IntelliJ IDEA
方法/步骤
项目路径,就是指classpath的根路径了。
是查找配置文件和classloader加载bytecode的起点
这次就以IntelliJ IDEA为例,来聊聊项目路径,也就是classpath的事
前面分享了一篇classpath和path的区别,有兴趣的tx可以去看看

使用Java API来查看。
Code:
public class ClassPathDemo {
public static void main(String[] args) {
String classPath = ClassPathDemo.class.getResource("/").getPath(); System.out.println("项目路径:" + classPath);

执行上述代码,看看打印的信息
Output:
项目路径:/E:/java/JavaStudy/out/production/JavaStudy/

在使用IDEA的过程,通过API查看项目路径来找编译好的class比较麻烦。
这个完全可以在IDEA的配置中的找嘛
下面就分享下在IDEA配置中怎么查看项目路径,也就是找到执行代码的classpath
在Project 面板中点右键,在弹出的菜单中选“Open Module Settings”

在弹出的“Project Structure”对话框中,选中“Paths”Tab选项卡
在Compiler output中,默认选择的是“Inherit project compile output path”
也就是当前module使用的是Project的Compiler output路径。
那么Project的Compiler output路径在哪呢?


点左侧的“Project”选项,在右侧窗口可以看到Project的compiler output
这个路径是不是和JAVA API的输入基本是一致的呢。
“This directory contains tow subdirectories:Production and Test for production code and test sources,respectively.”
java局域网获取项目路径
工具/原料
java
IntelliJ IDEA
方法/步骤
项目路径,就是指classpath的根路径了。
是查找配置文件和classloader加载bytecode的起点
这次就以IntelliJ IDEA为例,来聊聊项目路径,也就是classpath的事
前面分享了一篇classpath和path的区别,有兴趣的tx可以去看看

使用Java API来查看。
Code:
public class ClassPathDemo {
public static void main(String[] args) {
String classPath = ClassPathDemo.class.getResource("/").getPath(); System.out.println("项目路径:" + classPath);

执行上述代码,看看打印的信息
Output:
项目路径:/E:/java/JavaStudy/out/production/JavaStudy/

在使用IDEA的过程,通过API查看项目路径来找编译好的class比较麻烦。
这个完全可以在IDEA的配置中的找嘛
下面就分享下在IDEA配置中怎么查看项目路径,也就是找到执行代码的classpath
在Project 面板中点右键,在弹出的菜单中选“Open Module Settings”

在弹出的“Project Structure”对话框中,选中“Paths”Tab选项卡
在Compiler output中,默认选择的是“Inherit project compile output path”
也就是当前module使用的是Project的Compiler output路径。
那么Project的Compiler output路径在哪呢?


点左侧的“Project”选项,在右侧窗口可以看到Project的compiler output
这个路径是不是和JAVA API的输入基本是一致的呢。
“This directory contains tow subdirectories:Production and Test for production code and test sources,respectively.”
- 上一篇:乐心运动设置运动目标方法
- 下一篇:咪咕善跑修改登录密码教程
- 最近发表
- 赞助商链接