How to bypass NoClassDefFoundError of dedicated JSM classes by installing an application in JSw

Hi Guys,

I have a problem on how to best achieve the following requirement in the Jira DC add-on:

I created an application with a simple class that imports several classes dedicated to JSM.

I compiled the application by adding all the appropriate JSM dependencies as provided to the pom.xml file.

When I try to use this application in Jira Software, I get the obvious error java.lang.NoClassDefFoundError.

Do you have an idea how to bypass the problem of using dedicated classes from JSM in JSw? How to disable/deactivate those specific classes that have dependencies with JSM when installing this application in JSw?

My goal is to create a universal app that dynamically removes some functions if there is no JSM installed (or vice versa JSw).


Hi Adam,

It’s a hard path you’re on. Perfectly solvable, but it requires everything to be aligned properly.

The rule of thumb is you cannot instantiate classes which have an ‘import’ of a non-loaded class. That’s all, you can still refer to them using MyClass.class, or even use their static members. These classes just must never be loaded/instantiated if JSM isn’t here, notably they can’t directly be used in atlassian-plugin.xml.

Here’s how we do when we have a dynamic dependency between two plugins. It is not exactly your situation, since JSM isn’t something that customers can disable/enable in live, so the first step is optional for you.

First, optional for you, you would need to declare those packages in the <DynamicImport-Package> section in Maven, and remove them from <Import-Package> (i.e. Write ! in this section).

Second, in Java code, every time you want to use them, you’ll first check whether you’re allowed to call that class, then you’ll call your class for example using new MyService(all my arguments).

Last, since it will quickly become annoying to update the arguments of new MyService(args) as you inject services, you’ll want to use the auto-injection with autowireCapableBeanFactory.createBean(MyService.class) (from the package org.springframework.beans.factory.config.AutowireCapableBeanFactory).

1 Like

Hi @aragot

Thank you for the quick response and the right direction!

I just did some quick tests for a few classes using <DynamicImport-Package>, as per your suggestion and proper verification if I can use MyClass.class based on the JSM installed, everything works so far correct :slight_smile:

Now I need to expand it to more complicated cases and verify it on more cases and Jira versions :sweat_smile:

Thank you again for the tip.


1 Like