NoClassDefFoundError when executing package via a PostFunction, which was included in plugin?

I have included a class which uses MongoDB driver in a customfield plugin. The Mongo driver has been added as a dependency and as one of the Import Packages in the plugin pom file as per below.

<!-- https://mvnrepository.com/artifact/com.mongodb/mongo-->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.4.2</version>
<scope>provided</scope>
</dependency>
<Import-Package>org.bson.*;resolution:="optional", com.mongodb.*;resolution:="optional", org.springframework.osgi.*;resolution:="optional", org.eclipse.gemini.blueprint.*;resolution:="optional", *</Import-Package>

Everything has compiled and is well, however when I try to use the MongoClient class in a post function script (using script runner) the following error is returned:

java.lang.NoClassDefFoundError: com/mongodb/MongoClient
	at com.rs2.jira.plugin.customfield.jira.customfields.MongoHelper.<init>(MongoHelper.java:18) [?:?]
	at com.rs2.jira.plugin.customfield.jira.customfields.CarrierToDb.getMongoHelper(CarrierToDb.java:588) [?:?]
	at com.rs2.jira.plugin.customfield.jira.customfields.CarrierToDb$getMongoHelper.call(Unknown Source) [?:?]
	at Script262.run(Script262.groovy:23) [?:?]
	at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runScriptAndGetContext(ScriptRunnerImpl.groovy:158) [?:?]
	at com.onresolve.scriptrunner.runner.ScriptRunner$runScriptAndGetContext$0.callCurrent(Unknown Source) [?:?]
	at com.onresolve.scriptrunner.runner.ScriptRunnerImpl.runStringAsScript(ScriptRunnerImpl.groovy:146) [?:?]
	at com.onresolve.scriptrunner.runner.ScriptRunner$runStringAsScript.call(Unknown Source) [?:?]
	at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate.doScript(CustomScriptDelegate.groovy:66) [?:?]
	at com.onresolve.scriptrunner.canned.jira.utils.CustomScriptDelegate$doScript.call(Unknown Source) [?:?]
	at com.onresolve.scriptrunner.canned.jira.workflow.postfunctions.CustomScriptFunction.doScript(CustomScriptFunction.groovy:44) [?:?]

 

How is it possible that the class is not found, when it is explicitly provided?

1 answer

Hello!

In order to do this you need to use the @WithPlugin and the plugin that you have inserted the MongoDB driver into.

You have more information about this here.

If I can help you further let me know.

Cheers!

Dyelamos

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Monday in Agility Beta

We've moved!

A note to all watchers that we've moved to a new community home... https://community.atlassian.com/t5/Agility/ct-p/agility Please update your notification subscriptions to keep across the ...

56 views 0 2
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you