What is the best way to load the jira application context to get the context path?

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 27, 2012

Hi,

I am developing a plugin which requires the use of context path of jira for reading some resource files. I tried various ways for getting the path but failed and got strucked. I tried system.getEnv("CATALINA_HOME"), it is working in windows environment but returning null in linux environement. Any suggestion would be greatly appreciated.

-Srinivas

1 answer

1 accepted

0 votes
Answer accepted
tier-0 grump
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 28, 2012

Depends what you want to do - I'd reccomend using JIRA home to store resources rather than the web app folder. To get the home folder, do something like -

import com.atlassian.jira.config.util.JiraHome;
...
class MyPlugin {
    public MyPlugin(final JiraHome jiraHome)
    {
        //jiraHome.getHomePath() will give you home folder
    }
 

If you realy want to get the root contet path, then the best way is to do something like

  ServletContext servletContext = ServletContextProvider.getServletContext();
        if (servletContext == null)
        {
            log.error("No ServletContext exists.");
        }
        else
        {
            File webappServletPath = new File(servletContext.getRealPath("/"));

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 29, 2012

Hi James,

Since i donno how to get the reference of jiraHome, i tried using ServletContextProvider and i am able to get the context path. Thanks for your answer.

Appreciate if you could let me know the way to get the jiraHome reference.

Thanks,

Srinivas

Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2012

JiraHome is an interface, its implementation is retrieved through IoC in JIRA,

see http://confluence.atlassian.com/display/JIRA041/PicoContainer+and+JIRA and http://confluence.atlassian.com/display/JIRA041/Component+Plugin+Module for

srinivasp
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2012

Thanks for you answer.

I am getting the some exceptions while adding users to jira programatically. Could you please let me know how to resolve this in jira 4.4.4? in jira 4.0.2 the below function is working though the methods are deprecated.

public List<String> getActiveUsers(String ldapType, String sGroup)

throws EntityNotFoundException {

UserManager userManager = UserManager.getInstance();

Group grpJiraUser = userManager.getGroup(sGroup);

List<String> sUser = new ArrayList<String>(grpJiraUser.getUsers());

ArrayList<String> sCDCUsers = new ArrayList<String>();

Iterator<String> itUsers = sUser.iterator();

while (itUsers.hasNext()) {

String sUserName = (String) itUsers.next();

User usertoAct = userManager.getUser(sUserName);

String sUserEmail = usertoAct.getEmail();

if (sUserEmail.contains("@tibco-support.com")) {

sCDCUsers.add(sUserName);

}

}

if (ldapType.equalsIgnoreCase("PA")) {

sUser.removeAll(sCDCUsers);

return sUser;

} else

return sCDCUsers;

}

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events