java.lang.NoClassDefFoundError: org/jsoup/Jsoup

Dev Jira version: 9.12.11
Atlas-sdk: 9.0.2
JDK: 17

I’m using Jsoup in my Jira plugin.

Jsoup is a part of jira-core dependency

When i try install my plugin, without any changes in my pom.xml i have a exception:

com.atlassian.plugin.osgi.container.OsgiContainerException: Cannot start plugin: plugin_name
...
Caused by: org.osgi.framework.BundleException: Unable to resolve plugin_name [294](R 294.0): missing requirement [plugin_name [294](R 294.0)] osgi.wiring.package; (osgi.wiring.package=org.jsoup) Unresolved requirements: [[plugin_name [294](R 294.0)] osgi.wiring.package; (osgi.wiring.package=org.jsoup)]

I have a jsoup.jar in my Jira Instance WEB-INF/lib, and another plugins, like Scriptrunner use Jsoup without any exceptions (may be they have bundle with jsoup)

So, if i change my pom.xml Import section for this:

<Import-Package>
    org.springframework.osgi.*;resolution:="optional",
    org.eclipse.gemini.blueprint.*;resolution:="optional",
    *;resolution:="optional"
</Import-Package>

Plugin was successful installed.

But when i execute operation with Jsoup, i caught exception:

java.lang.NoClassDefFoundError: org/jsoup/Jsoup
...
Caused by: java.lang.ClassNotFoundException: org.jsoup.Jsoup not found by plugin_name [295]

When i added dependency in plugin pom.xml:

<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>${jsop.version}</version>
    <scope>provided</scope>
</dependency>

i have same exception.

Only one solution works for me: add jar in bundle (scope - compiled) and add exclusion to amps banned dependency:

<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>${jsop.version}</version>
</dependency>
...
<banningExcludes>
    <exclude>org.jsoup:jsoup</exclude>
</banningExcludes>

But honestly, i’m not a big fan of this kind of solution.

Can someone help with better solution? Have no idea

Hello mikhail,
for me it sounds like you’re facing a class loading issue with Jsoup in your Jira plugin.
Here are a few steps you can take to resolve this:

  1. Ensure Jsoup Dependency is Correct: Make sure that the Jsoup dependency is correctly defined in your pom.xml:
<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>1.14.3</version>
    <scope>compile</scope>
</dependency>

Using compile scope ensures that the dependency is included in the plugin’s bundle.
2. Check for Conflicting Dependencies: Sometimes, other plugins or dependencies might include conflicting versions of Jsoup. Ensure that there are no conflicting dependencies in your pom.xml or in other plugins.
3. Bundle Jsoup with Your Plugin: If the above steps don’t work, you can bundle Jsoup with your plugin by including it in the plugin’s bundle:

<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>1.14.3</version>
    <scope>compile</scope>
</dependency>

This ensures that Jsoup is available to your plugin at runtime.
4. Exclusion in Banned Dependencies: If you still encounter issues, you can exclude Jsoup from the banned dependencies:

<banningExcludes>
    <exclude>org.jsoup:jsoup</exclude>
</banningExcludes>
  1. Clean and Rebuild: Perform a clean and rebuild of your project to ensure that all dependencies are correctly resolved:
mvn clean install 

or

atlas-clean
  1. Check OSGi Configuration: Ensure that your OSGi configuration is correct and that the required packages are imported:
<Import-Package>
    org.jsoup.*;resolution:=optional,
    *;resolution:=optional
</Import-Package>

By following these steps, you should be able to resolve the class loading issue with Jsoup in your Jira plugin.

Hopefully it will help ::slight_smile:

Best regards,
Daniel

Hello, Daniel! I’m do all this steps in my workaround solution exactly

Question is “How to do this without workaround”.
Jsoup should work with “provided” scope, cause Jira have it. But in case of Jsoup plugin cannot find it.
If we add this dependency as compiled, our jar will be bigger for 700kb, if i remember right.

It’s not a big issue, but i think that it must work with provided scope

Hey there! Mikhail.
To ensure that Jsoup works with the “provided” scope in Jira, you might want to double-check a few things:

  1. ClassPath Issue: Ensure that Jsoup is on the classpath of the Jira instance. Sometimes, the “provided” scope might not place it correctly.
  2. Dependency Management: Make sure your pom.xml file includes the correct dependency scope:
<dependency>
    <groupId>org.jsoup</groupId>
    <artifactId>jsoup</artifactId>
    <version>1.14.2</version>
    <scope>provided</scope>
</dependency>
  1. Bundling the Plugin: Sometimes, despite using the “provided” scope, the class loader might not find Jsoup. In this case, creating an OSGi bundle for Jsoup and including it in your plugin might help.
  2. Check Jira Version Compatibility: Ensure that the version of Jsoup you are using is compatible with the version of Jira you are running.

Hope thats what you looking for.

Best regards
Daniel