I’m working on a Jira plugin and I’m stuck on something. I’ve got a properties file called config.properties in my plugin structure. The thing is, I’m not sure how to find its location after I install the plugin on a Jira server.
Does anyone know how to get the path of resource files in a Jira plugin? I’ve looked through the docs but couldn’t find anything helpful. It would be great if someone could point me in the right direction or share some code examples.
I’m using the latest Atlassian SDK if that helps. Thanks in advance for any tips or advice!
As someone who’s developed several Jira plugins, I can share a reliable approach I’ve used for accessing resource files. Instead of trying to locate the physical file path, which can be tricky due to Jira’s deployment structure, I’ve had success using the ClassPathResource from Spring Framework.
Here’s a snippet that’s worked well for me:
ClassPathResource resource = new ClassPathResource("config.properties");
Properties props = new Properties();
props.load(resource.getInputStream());
This method is deployment-agnostic and works seamlessly whether you’re running in development or production environments. It’s also quite flexible - you can use it for any resource file, not just properties.
One tip: make sure your resource file is in the correct directory in your project structure, typically under src/main/resources. This ensures it’s properly packaged with your plugin JAR.
Hope this helps with your plugin development, Zack!
For accessing resource files in Jira add-ons, I’ve found the Plugin Framework’s PluginResourceLoader to be quite useful. You can inject it into your class and use it like this:
@ComponentImport
private final PluginResourceLoader resourceLoader;
public YourClass(PluginResourceLoader resourceLoader) {
this.resourceLoader = resourceLoader;
}
This approach has worked well for me across different Jira versions and deployment scenarios. It handles the file location abstraction for you, which is quite convenient.