在类库的开发过程中,有些时候为了self-contain的原因,我们希望所有的资源都打包在jar中,但是有些工具好像无法支持从classpasth直接获取比如velocity的模板合并,此时我们就知道class所在的jar,然后通过jar方式加载velocity资源模板。

String jarFilePath = clazz.class.getProtectionDomain().getCodeSource().getLocation().getFile();  
// URL Decoding  
jarFilePath = java.net.URLDecoder.decode(jarFilePath, "UTF-8"); 

 

  1. String jarFilePath = clazz.class.getProtectionDomain().getCodeSource().getLocation().getFile();  
  2. // URL Decoding  
  3. jarFilePath = java.net.URLDecoder.decode(jarFilePath, "UTF-8"); 

相关文章:

  • 2022-12-23
  • 2022-01-14
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-01
  • 2021-11-27
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案