J tricks - Little JIRA Tricks
  • Home
  • Plugins ↓
    • JQL Tricks Plugin
      • JQL Tricks Plugin - Cloud
        • JQLT Cloud Installation
        • JQLT Cloud Configuration
        • JQLT Cloud Usage
        • JQLT Cloud License
        • JQLT Cloud FAQ
      • JQL Tricks Plugin - DC
        • JQLT DC Installation
        • JQLT DC Configuration
        • JQLT DC Usage
          • JQLT Issue Functions
          • JQLT Subtask Functions
          • JQLT Links Functions
          • JQLT Development Functions
          • JQLT Worklog Functions
          • JQLT Project Functions
          • JQLT Component Functions
          • JQLT Version Functions
          • JQLT Group Functions
          • JQLT User Functions
          • JQLT Date Functions
        • JQLT DC License
        • JQLT DC FAQ
        • JQLT DC Known Issues
        • JQLT DC Performance
      • JQL Tricks Cloud Migration
    • Simplified Planner
      • J-Planner Installation
      • J-Planner Configuration
      • J-Planner Usage
        • Creating a plan
        • Editing a plan
        • Deleting a plan
        • Viewing a plan
        • Modifying a plan
      • J-Planner FAQ
    • Atla-Search Plugin
      • Atla-Search Installation
      • Atla-Search Configuration
      • Atla-Search Usage
      • Atla-Search License
      • Atla-Search FAQ
    • Heroku for Compass App
      • Heroku for Compass Installation
      • Heroku for Compass Configuration
      • Heroku for Compass Usage
    • Copy to subtask Plugin
    • All Plugins
  • Tutorials
  • The Book
  • Contact Us
  • Home
  • Plugins ↓
    • JQL Tricks Plugin
      • JQL Tricks Plugin - Cloud
        • JQLT Cloud Installation
        • JQLT Cloud Configuration
        • JQLT Cloud Usage
        • JQLT Cloud License
        • JQLT Cloud FAQ
      • JQL Tricks Plugin - DC
        • JQLT DC Installation
        • JQLT DC Configuration
        • JQLT DC Usage
          • JQLT Issue Functions
          • JQLT Subtask Functions
          • JQLT Links Functions
          • JQLT Development Functions
          • JQLT Worklog Functions
          • JQLT Project Functions
          • JQLT Component Functions
          • JQLT Version Functions
          • JQLT Group Functions
          • JQLT User Functions
          • JQLT Date Functions
        • JQLT DC License
        • JQLT DC FAQ
        • JQLT DC Known Issues
        • JQLT DC Performance
      • JQL Tricks Cloud Migration
    • Simplified Planner
      • J-Planner Installation
      • J-Planner Configuration
      • J-Planner Usage
        • Creating a plan
        • Editing a plan
        • Deleting a plan
        • Viewing a plan
        • Modifying a plan
      • J-Planner FAQ
    • Atla-Search Plugin
      • Atla-Search Installation
      • Atla-Search Configuration
      • Atla-Search Usage
      • Atla-Search License
      • Atla-Search FAQ
    • Heroku for Compass App
      • Heroku for Compass Installation
      • Heroku for Compass Configuration
      • Heroku for Compass Usage
    • Copy to subtask Plugin
    • All Plugins
  • Tutorials
  • The Book
  • Contact Us

Reading from property file in v2 plugins

8/12/2012

3 Comments

 
This is going to be a quick one. How do one read from a property file in a JIRA v2 plugin?

Yeah, I know. It is pretty simple. But there are few who are stuck with it - as you can see from this thread.

And there are 2 use cases here:

  1. Read a property file from the WEB-INF/classes folder in the JIRA installation directory. Remember, the absolute path can be different in different installations and based on different Operation systems.

    But should we care? Not much because Atlassian already have put in the effort to load property files from WEB-INF/classes folder in a fault tolerant manner that works across different applications servers.

    Here is how you load the properties:

    InputStream iStream = ClassLoaderUtils.getResourceAsStream("jtricks.properties", this.getClass());
    Properties p = new Properties();
    p.load(iStream);


    where ClassLoaderUtils is com.atlassian.plugin.util.ClassLoaderUtils.

    The individual values can be read using the respective key as follows:

    p.getProperty("test.key")

  2. Read a property file from JIRA Home and protect it from JIRA upgrades.

    This is also pretty easy because the JIRA Home folder is already stored in database and can be retrieved using JiraHome.class. Loading properties is then a piece of cake.

    File jiraHome = ComponentAccessor.getComponent(JiraHome.class).getHome();
    File propertyFile = new File(jiraHome, "jtricks-home.properties");
    FileInputStream fileInputStream = new FileInputStream(propertyFile);
    Properties p = new Properties();
    p.load(fileInputStream);


    The individual values can be read using the respective key as we did in the first case:

    p.getProperty("test.key")

Major differences between the two?
  • Properties in Method 1 are loaded during startup and requires a restart if the property values are modified
  • Depending up on how frequently the properties are read, Method 1 might perform better
  • Method 1 is not tolerant to upgrades. Make sure to copy the property file to WEB-INF/classes folder of new JIRA installation during upgrades
Attached servlet plugin has the full code for both methods. The servlet can be run at /plugins/servlet/readproperties. For more about servlets, check out the JIRA Development cookbook.

read-properties.zip
File Size: 23 kb
File Type: zip
Download File

3 Comments
Matt Doar link
8/13/2012 06:15:25 am

Property files drive me crazy during upgrades. It's so much nicer to have the data configured within JIRA and stored in the existing properties table or Active Objects tables. That also helps with not having to restart JIRA to have a changed value take affect.

Handy snippet for getting jira.home though!

Reply
J-Tricks
8/13/2012 03:47:48 pm

I always prefer that (storing configuration data using AO) but sometimes end up doing property files because of tight estimates or customer recommendation :)

Thought to share when I saw that question in Answers.

Reply
Letting Newquay link
9/24/2012 10:43:42 pm

All the contents you mentioned in post are too good and can be very useful. I will keep it in mind, thanks for sharing the information keep updating, looking forward for more posts. Thanks

Reply

Your comment will be posted after it is approved.


Leave a Reply.

    Enter your email address:

    Author

    Jobin Kuruvilla - Works in Adaptavist as Head of DevOps Professional Services. 

    Author of JIRA Development Cookbook and JIRA 5.x Development Cookbook.


    RSS Feed

    Categories

    All
    Acive Objects
    Ajs
    Book
    Components
    Condition
    Custom Fields
    Customization
    Events
    Gadgets
    Javascript
    Jql
    Listener
    Mail
    Permissions
    Plugin Framework
    Post Function
    Properties
    Remote Invocation
    Reporting
    Rest
    Scheduled Tasks
    Search
    Services
    Soap
    Summit
    User Interface
    Validator
    Webwork Actions
    Workflow

    Archives

    October 2016
    August 2016
    March 2016
    January 2016
    December 2015
    May 2014
    December 2013
    November 2013
    July 2013
    June 2013
    April 2013
    October 2012
    September 2012
    August 2012
    July 2012
    May 2012
    March 2012
    February 2012
    January 2012
    December 2011
    November 2011
    June 2011
    May 2011
    April 2011
    March 2011
    February 2011
    January 2011
    November 2010
    October 2010
    September 2010
    August 2010

SUPPORT
APPS
TUTORIALS
THE BOOK
© J-Tricks