I’m working on a Jira plugin and I need help with accessing resource files. I have a configuration file called config.properties in my plugin structure. When I deploy this plugin to different Jira servers, I can’t figure out how to get the correct file path to read from this properties file.
I’ve tried using relative paths but they don’t work consistently across different environments. The file location seems to change depending on where Jira is installed and how the plugin gets deployed.
Can someone explain the proper way to locate and access resource files from within a Jira plugin? I need a solution that works regardless of the target Jira installation path.
Any help would be appreciated.
When I encountered a similar issue with accessing resource files in Jira plugins, I found that utilizing the ClassLoader is a reliable approach. Instead of hardcoding file paths, you can access your configuration file by using getClass().getClassLoader().getResourceAsStream("/config.properties")
. This method treats your properties file as part of the plugin JAR, ensuring that it is read correctly regardless of the Jira installation path. Just make sure to place your config.properties file in the src/main/resources directory to ensure it is packaged correctly. This approach has proven effective for various Jira versions and deployment environments.
i tried both methods but found something simpler that works. use this.getClass().getResource("/config.properties")
- it gives you the url directly without messing with input streams. just don’t forget to check for null if the file’s missing. tested it across different jira versions and it’s solid.
I encountered the same issue while developing Jira plugins for different environments. The key is recognizing that Jira plugins are OSGi bundles, which means standard file system access techniques may not yield reliable results. Instead, use ComponentAccessor.getPluginAccessor() to retrieve your plugin instance and call getResourceAsStream() from the plugin’s class loader. Ensure your properties file is located in src/main/resources and reference it without a leading slash. This method has proven effective across development, staging, and production environments, without path discrepancies.