问题:

打包成jar之后,读取resources里面的文件出现:java.io.FileNotFoundException: class path resource  cannot be resolved to URL because it does not exist

原来的代码工程读取resources目录下的文件是OK的。

原因:

打包成jar文件之后,原来在resources的文件存储路径发生改变了。

解决:

使用this.getClass().getResourceAsStream("文件名")来读取,比如

InputStream fileKeyStore = this.getClass().getResourceAsStream( "sslKeyStore_FileName.pfx" );

详细请参考这边文章:

文章:How to Avoid the Java FileNotFoundException When Loading Resources

链接:https://www.baeldung.com/java-classpath-resource-cannot-be-opened

 

更多推荐