Getting IllegalStateException when using ComponentAccessor in Jira plugin development

I’m working on a Jira plugin and keep running into this error when I try to run my code:

IllegalStateException: ComponentAccessor has not been initialised

I’ve looked at similar questions but can’t find a working solution. Here’s what I’m trying to do:

package com.example.jira.tools;

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.MutableIssue;

public class FieldRetriever {

    public static void main(String[] args) {
        String ticketKey = "PROJ-123";
        String fieldName = "Development Status";
        
        // Fetch the ticket
        MutableIssue ticket = ComponentAccessor.getIssueManager().getIssueByCurrentKey(ticketKey);
        
        // Extract custom field data
        Object statusValue = ticket.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(fieldName));
        
        System.out.println(statusValue);
    }
}

Basically I want to get a custom field value from a Jira issue but the ComponentAccessor seems to not be working properly. What am I missing here?

ComponentAccessor needs Jira’s container fully loaded before it can grab components. Your main method runs outside Jira’s runtime, so those components just aren’t there. I hit this same wall when I started writing Jira plugins. Move your code into an actual plugin component - servlet, REST resource, or event listener. These run after Jira’s dependency injection sets everything up. Want to test it? Write unit tests with Jira’s testing framework or make a simple REST endpoint you can hit after deploying the plugin.

componentaccessor dont work in a normal main method. it needs to run inside jira context. try moving ur logic to a servlet or rest endpoint where it will initialize properly.

You’re hitting this because you’re trying to access Jira components before the app context loads. ComponentAccessor wraps Spring’s dependency injection container, which isn’t available until Jira finishes starting up. Running code through a main method skips this entirely. I ran into this exact issue on my first plugin and wasted hours debugging it. You need a proper plugin entry point instead. Try a web action, workflow post-function, or simple web panel - whatever fits your use case. These get created within Jira’s managed lifecycle, so ComponentAccessor can actually reach all the registered beans. Also worth checking your atlassian-plugin.xml has the right component imports and your plugin dependencies are set up correctly.