Tomcat发布项目可以正确获取resources目录下的密钥, Eclipse启动项目, 密钥找不到, 导致加解密报错
public class Test {
public static void main(String[] args) {
A a = new A();
System.out.println(a.path);
}
}
class A{
public static String path = new Object() {
public String getPath() {
return this.getClass().getResource("/").getPath();
}
}.getPath().substring(1);
}
1. 控制台输出结果
E:/project/4coding/项目名称/target/test-classes/
2. 路径执指向target目录, 并不是我想要的resources目录
3. Eclipse中查看文件属性, 使用绝对路径可以正确访问
Java获取maven项目resources目录,Eclipse和Tomcat中路径差异
最新推荐文章于 2022-05-18 16:29:54 发布