LinkageError accessing Structure API from another plugin

39 views
Skip to first unread message

tony....@intunity.com.au

unread,
Nov 21, 2012, 10:16:07 PM11/21/12
to structure-pl...@googlegroups.com
Hi Igor,

I am writing a custom plugin which accesses the structure API.

I am able to retrieve a Structure for a given Issue ID, and can call methods on Structure without any problems. However when I call a method on Forest I get a runtime error saying:

java.lang.LinkageError: loader constraint violation: loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoader) previously initiated loading for a different type with name "com/almworks/jira/structure/api/forest/Forest"
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
	at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.findClass(ModuleImpl.java:1829)
	at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:716)
	at org.apache.felix.framework.ModuleImpl.access$200(ModuleImpl.java:73)
	at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1690)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

Forest is inside the same structure-api jar as Structure, so I don't understand why there appears to be a problem with the class loading just for the Forest class.

I am developing in Eclipse and have created an Eclipse-configured Plugin project following the instructions at https://developer.atlassian.com/display/DOCS/Set+Up+the+Eclipse+IDE+for+Windows.

My pom.xml contains:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.docx4j</groupId>
<artifactId>docx4j</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>com.almworks.jira.structure</groupId>
<artifactId>structure-api</artifactId>
<version>7.1.0</version>
<scope>provided</scope>
</dependency>

I have installed the structure-1.7.1.jar in my local development Jira instance (created from running atlas-run) and am using the fastdev approach for deploying plugin changes to Jira.

I have manually added the structure-api jar to my project classpath, so that Eclipse can resolve the imports and also because Jira was giving a runtime ClassNotFound error for StructureServices when I didn't do this (My plugin installs ok through fastdev, but when I access it in Jira the error occurs).

Any ideas about what I might be doing wrong?

Thanks,
Tony

Igor Sereda

unread,
Nov 22, 2012, 3:02:02 AM11/22/12
to structure-pl...@googlegroups.com

Hi Tony,

 

This error likely means that you have multiple versions of the API in your plugin’s classpath, or the same version but several times.

 

I would suggest to try the following:

-          Stop JIRA;

-          Completely delete directory target/classes;

-          Delete target/your-plugin.jar

-          Remove your-plugin.jar and other jars with just numbers in their name from target/jira/home/plugins/installed_plugins

-          Completely remove target/jira/home/plugins/.osgi-bundles

-          (OR, instead of hand-picked removals, you can do mvn clean just for sure, but that will wipe out your debug jira data too)

-          Do atlas-run again

-          Check if the plugin is working – without letting fastdev run

 

If that helps, it’s likely the fastdev’s fault. It is known, for example, for dumping all dependencies in your plugin JAR as classes, not as jars in META-INF. In that case, turn fastdev off and use “pi” command from atlas-cli. That’s what we do, by the way.

 

Other causes I might think of:

-          Using your IDE’s debugging capabilities to dynamically reload changed classes (even your own);

-          Depending on another artifact or importing another plugin’s services, which transitively depends on a different version of Structure API – could be checked with mvn dependency:tree

 

Hope this helps!

Igor

Reply all
Reply to author
Forward
0 new messages