Locating Resource Files in Custom Jira Add-ons

Hey everyone,

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 once I’ve installed the plugin on a Jira instance.

Does anyone know how to figure out where these resource files end up? It would be super helpful to understand this for debugging and future updates.

I’ve tried looking through the Jira docs but couldn’t find a clear answer. Any tips or tricks you’ve used in your own plugin development would be awesome!

Thanks in advance for any help you can give. I’m pretty new to Jira plugin dev, so I really appreciate the support from this community.

When developing Jira plugins, locating resource files can be tricky. In my experience, the best approach is to use the classloader to access your properties file. You can do this with:

getClass().getClassLoader().getResourceAsStream("config.properties")

This method works regardless of where the file ends up after installation. It’s particularly useful because Jira may reorganize your plugin’s file structure during deployment.

If you need the actual file path for some reason, you can use:

getClass().getClassLoader().getResource("config.properties").getPath()

However, I’d caution against relying on file paths directly, as they can change between Jira versions or deployments. Sticking with the classloader method has saved me countless headaches in plugin development.

hey there! i’ve run into this before. try using the PluginResourceLoader class from the atlassian-plugins-api. it’s super handy for grabbing resource files in your addon. just inject it into ur component and use the getResourceAsStream() method. works like a charm and keeps things clean. good luck with ur plugin!

I’ve been down this road before, and I can tell you it can be a bit of a maze. One approach that’s worked well for me is using the ComponentAccessor class. It provides a nifty way to access various Jira components, including the plugin system.

Here’s what I’ve found effective:

PluginAccessor pluginAccessor = ComponentAccessor.getPluginAccessor();
Plugin plugin = pluginAccessor.getPlugin("your.plugin.key");
ClassLoader classLoader = plugin.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream("config.properties");

This method gives you direct access to your resource file, regardless of where it ends up after installation. It’s been reliable across different Jira versions in my experience.

Just remember to handle exceptions and close the input stream properly. Hope this helps with your plugin development!