Reading a properties file from a plugin JAR file from my Custom Controller

I am trying to read a properties file from my custom controller with no luck. My
file resides in the siteminderPlugin.jar\buildServerResources\ folder. I am trying to access the
file with the code snippet below. Any help of how to read a properties file in a plugin Jar would be appreciated.

try {
             String path = myPluginDescriptor.getPluginResourcesPath("");
             InputStream in = this.getClass().getClassLoader().getResourceAsStream(path);
                File propFile = new File(path);
                Properties properties = new Properties();
                if(propFile.exists()) {
                   properties.load(new FileInputStream(propFile));
                   sysAdminSSOId = properties.getProperty("MY.ID");
                   logoutUrl = properties.getProperty("MY.URL");
         }catch(IOException ex) {
             log.error("Error reading properties file: " + ex.getMessage());

Comment actions Permalink

The content of buildServerResources directory will be unpacked to the webapps/plugins/<plugin_name>/ directory. So PluginDescriptor will return path to the unpacked content of this directory. It is supposed that under the buildServerResources you keep only those files that need to be accessible from the web. I do not think file is such a case. If you do not need to update it often, you can put it inside your jar file but not under the buildServerResources. Then you'll be able to use code like the one you already written.

Alternatively, you can provide some customization parameters for your plugin right in the teamcity-plugin.xml file and read them using PluginDescriptor.getParameterValue method. Something like this:
    <parameter name="param name">value</parameter>

Comment actions Permalink

Pavel the alternative seems like a cleaner solution so I will use that approach.


Please sign in to leave a comment.