Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community Forumsjava.lang.LinkageError
https://www.eclipse.org/forums/index.php/mv/msg/32024/103926/#msg_103926
Originally posted by: ysralmasri.yahoo.com
Hello,
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);
parser.parse(inputSource);
log.debug("Parsing finished");
strReader.close();
} 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?]]>2008-01-16T13:39:32-00:00Re: java.lang.LinkageError
https://www.eclipse.org/forums/index.php/mv/msg/32024/103971/#msg_103971
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.
Tom]]>Thomas Watson2008-01-17T17:03:48-00:00Re: java.lang.LinkageError
https://www.eclipse.org/forums/index.php/mv/msg/32024/104004/#msg_104004
Originally posted by: ysralmasri.yahoo.com
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,
Yasser]]>2008-01-18T13:40:21-00:00Re: java.lang.LinkageError
https://www.eclipse.org/forums/index.php/mv/msg/32024/104615/#msg_104615
Originally posted by: yubo.fan.sas.com
Tom,
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 manifest.mf 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]]>2008-02-01T14:28:31-00:00Re: java.lang.LinkageError
https://www.eclipse.org/forums/index.php/mv/msg/32024/104697/#msg_104697
Originally posted by: ysralmasri.yahoo.com
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.