Jira Plugin Development: 'ComponentAccessor Not Initialized'

Running my Jira Java plugin results in a ComponentAccessor initialization error. Assistance is needed to properly fetch and display a custom field’s value. See example:

package my.plugin.sample;

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

public class JiraComponentTest {
    public static void main(String[] args) {
        String ticketKey = "CAP-123";
        String customFieldName = "Example Custom Field";
        
        MutableIssue ticket = ComponentAccessor.getIssueManager().getIssueByCurrentKey(ticketKey);
        Object fieldValue = ticket.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(customFieldName));
        
        System.out.println("Custom Field Value: " + fieldValue);
    }
}

hey, your code is runing as a standalone app. componentaccessor needs jira osgi context so try running it as a proper plugin module inside jira. good luck!