Search code examples
pathsdkosgijiraosgi-bundle

How to set system property with path of resource [Jira plugin, OSGI]


I want to use System.setProperty("javax.net.ssl.trustStore", path) where path points to jks certificate which is in project's resources. The problem is my project is jira plugin and it uses OSGI. When I use getClass.getResource("certificate.jks") I get path = "bundle://..." and then certificate isn't found. I also tried to put there just "/certificate.jks" but it didn't work too.

Do you have some ideas how to solve this problem? Thank you in advance for any ideas!


Solution

  • One solution is to use Bundle.getEntry("path/to/your/trust/store/file/relative/tobundle/root") then do toURI to get a File that you can open and get the string value and then use that value to set the system property you mentioned in your question. Bundle.getResource method will search classpath of other imported bundles. If this does not work then try doing Bundle.getClassLoader() to load the resource you want because you are probably getting a different class loader as each bundle uses their own. Hope this answers yoru quesiton.