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 plugin.properties
file resides in the siteminderPlugin.jar\buildServerResources\ folder. I am trying to access the plugin.properties
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("plugin.properties");
             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());
         }

2 comments

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 plugin.properties 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:
  <parameters>
    <parameter name="param name">value</parameter>
  </parameters>

0

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

0

Please sign in to leave a comment.