在maven工程中,如果想获取src/main/resources 的路径,方法1Thread.currentThread().getContextClassLoader(). getResource(".").getPath() 这样获取出来的路径是在target/classes 这个目录下。方法2:this.getClass().getClassLoader().getResource("config.properties").getPath();
Maven工程资源路径获取
本文介绍了在Maven项目中如何获取src/main/resources目录的路径。提供了两种方法:使用Thread.currentThread().getContextClassLoader().getResource(.).getPath()和this.getClass().getClassLoader().getResource(config.properties).getPath()。
在maven工程中,如果想获取src/main/resources 的路径,方法1Thread.currentThread().getContextClassLoader(). getResource(".").getPath() 这样获取出来的路径是在target/classes 这个目录下。方法2:this.getClass().getClassLoader().getResource("config.properties").getPath();
1971

被折叠的 条评论
为什么被折叠?