JAXB API issue in Jira plugin: 'com.sun.xml.bind.v2.ContextFactory' provider missing

I’m having trouble with my Jira plugin that uses JAXB for XML parsing. It works fine when I run it from the command line, but it breaks when I put it in Jira as a plugin. Here’s what’s happening:

My code looks something like this:

import javax.xml.bind.*;

class XMLHandler {
  public void processXML() {
    // JAXB stuff here
  }

  public static void main(String[] args) {
    XMLHandler handler = new XMLHandler();
    handler.processXML();
  }
}

When I run it normally, everything’s cool. But in Jira, I get this error:

javax.xml.bind.JAXBException: Provider com.sun.xml.bind.v2.ContextFactory not found

It’s weird because it’s the same machine. The only difference I can think of is that Jira doesn’t use the main() method, it just calls processXML() directly.

Any ideas why this is happening or how to fix it? I’m scratching my head here!

I’ve run into this issue before with Jira plugins. The problem is likely due to how Jira manages its classpath and dependencies. When you run your code standalone, it’s using the JDK’s built-in JAXB implementation. But Jira might be using a different classloader or have its own JAXB version.

To fix this, try explicitly adding the JAXB API and implementation as dependencies in your plugin’s pom.xml file. Something like:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
    <version>2.3.1</version>
</dependency>

This should ensure your plugin has access to the necessary JAXB classes within Jira’s environment. Also, double-check your plugin’s manifest to make sure it’s not conflicting with Jira’s internal libraries. If the issue persists, you might need to use a different XML parsing approach that’s more compatible with Jira’s ecosystem.

hey noah, i’ve seen this before. jira’s weird with classpath stuff. try adding jaxb dependencies to ur pom.xml. like this:

javax.xml.bind jaxb-api 2.3.1

if that dont work, maybe use jira’s xml tools instead? they usually play nice with the plugin system.

This issue often stems from class loading conflicts in Jira’s OSGi environment. The plugin system isolates dependencies, which can lead to JAXB classes being unavailable. A potential workaround is to use Jira’s built-in XML parsing utilities instead of JAXB. Alternatively, you could try bundling the necessary JAXB classes with your plugin, ensuring you set the correct Import-Package and Export-Package headers in your manifest.

If you decide to stick with JAXB, make sure you’re using a version compatible with your Jira instance. Also, consider using the JAXB implementation provided by Jakarta XML Binding, as it’s the path forward for Java EE technologies.

Lastly, check if your plugin is properly declaring its dependencies in the atlassian-plugin.xml file. Sometimes, explicitly stating the required libraries can resolve class loading issues in the Jira environment.