Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » java.lang.LinkageError
java.lang.LinkageError [message #103926] Wed, 16 January 2008 13:39 Go to next message
Eclipse UserFriend
Originally posted by:


I'm using 3 bundles A B & C. A is the core bundle that contains all
necessary libs, and it takes care of exporting any packages needed by
other bundles. All my logic resides in B, and C is merely an activator
that looks up services and calls methods on B.

In B I have the following method:

public Document parseXMLString(String aXMLStr) throws ParseException {
log.debug("XML to be parsed is : " + aXMLStr);
DOMParser parser = new DOMParser();
try {
log.debug("Started parsing");
StringReader strReader = new StringReader(aXMLStr);
InputSource inputSource = new InputSource(strReader);
log.debug("Parsing finished");
} catch (IOException ex) {
throw new ParseException("IO Exception", ex);
} catch (SAXException saxEX) {
throw new ParseException("Parse Exception", saxEX);
return parser.getDocument();

Now A contains sax.jar, dom.jar and jaxp-api.jar that has all XML related
stuff, and B has org.xml.sax, org.w3c.dom in its Import-Package part.
When my code runs, I have the following exception:

java.lang.LinkageError: loader constraints violated when linking
org/xml/sax/InputSource class

pointing to the line: parser.parse(inputSource)

I know that this package also exists in the JDK so it's mixed up on it as
to where to get this class from.

I tried to get rid of sax.jar and remove it from A's class path so to
convince B to get org.xml.sax.* from the JDK itself. But now I got the
following error:

java.lang.LinkageError: loader constraints violated when linking
org/w3c/dom/Document class

pointing to return parser.getDocument();

That's an expected result, and the first thing one will think of is
getting rid of dom.jar!

When I did that, I have compile error saying that:

The type org.w3c.dom.ranges.DocumentRange cannot be resolved. It is
indirectly referenced from required .class files

It's pointing to a class in bundle B.

Here I'm stuck; org.w3c.dom.ranges package just doesn't exist in the JDK
and it's only there in the dom.jar.

Any thoughts?
Re: java.lang.LinkageError [message #103971 is a reply to message #103926] Thu, 17 January 2008 17:03 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 476
Registered: July 2009
Senior Member
Hi Yasser,

In A you export all the packages contained in the library jars. Do you
include a version on the exports? I recommend trying to include a
version. For example:

Bundle-SymbolicName: A
Export-Package: org.w3c.dom.ranges; version="2.1"

Bundle-SymbolicName: B
Import-Package: org.w3c.dom.ranges; version="2.1"

This will force B to get org.w3c.dom.ranges from A because the
system.bundle does not export the org.w3c.dom.ranges at any version.
You should add versions to all packages exported by A. I used version
"2.1" above for an example, you should use what ever version is
appropriate for the libraries you are exporting.

Re: java.lang.LinkageError [message #104004 is a reply to message #103971] Fri, 18 January 2008 13:40 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:

Thanks Tom, you're the saver this list ;)

Yep you're right, returning that jar to A and adding a version to the
exports will make it clear to B which version it should select. That
solves my problem!

Much appreciated,

Re: java.lang.LinkageError [message #104615 is a reply to message #103971] Fri, 01 February 2008 14:28 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by:


I'm running into a very similar problem to the above one. I got the exact the same error. My scenario is as follows:

Project A: Eclipse RCP plug-in depends on Project B
It calls a method in another jar that uses org.xml.sax.*

Project B: a simple bundle of dependency jars, including dom4j.jar

I see that I can modify the file in B to include versions. However, I don't see a way to modify the Import-Package in A. In the BuildPath dialog, I can only see that the dependency jars are in the list, but there is no way to edit them or add versions.

Please let me know if you have any ideas. Thanks inadvance for your time.

- Yubo
Re: java.lang.LinkageError [message #104697 is a reply to message #104615] Mon, 04 February 2008 07:04 Go to previous message
Eclipse UserFriend
Originally posted by:

Hello Yubo,

Both Import-Package and Export-Package support version numbers in their
syntax. When you go to Dependencies tab and press "Add..." button in
Imported Packages you should find a version number next to any package
that was exported with a version. You can also include this manually (you
don't need to) by editing the manifest file.

Previous Topic:Hard to work with osgi.bundles paramter in config.ini
Next Topic:Usage of split packages?
Goto Forum:

Current Time: Thu Mar 23 00:37:32 GMT 2017

Powered by FUDForum. Page generated in 0.01669 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software