I have a bit of a problem with my plugin. Let's say I create my plugin A, in my pom.xml I have defined a dependency on B which is a jar with external API. Everything is nice and my B.jar gets included in A.jar under META-INF\lib\B.jar
The problem is that B.jar uses javax.xml.parsers - probably would be quite easy to solve it would be a dependency somewhere... instead seems to me that someone just copied over the entire jaxp code into B.jar so the jar archives are in general like:
A.jar (my plugin)
- com
- something
- META-INF
- lib
- B.jar
B.jar (jar that I use)
- com
- otherthing
- ClassB.class
- javax
- xml
- parsers
- DocumentBuilderFactory.class
Then in ClassB.class they try to do something with XML which goes to DocumentBuilderFactory.class where the following code
public static DocumentBuilderFactory newInstance() { try { return (DocumentBuilderFactory)FactoryFinder.find("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); } catch (FactoryFinder.ConfigurationError localConfigurationError) { } throw new FactoryConfigurationError(localConfigurationError.getException(), localConfigurationError.getMessage()); }
returns org.apache.xerces.jaxp.DocumentBuilderFactoryImpl while in ClassB.class they expect it to be javax.xml.parsers.DocumentBuilderFactory so I get to a
java.lang.ClassCastException: org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java)
The obvious question is how do I deal with that?
Community moderators have prevented the ability to post new answers.
Took me a while but I got it.
java.xml.parsers.* is already bundled with Jira. There's a conflict since B.jar contains same package/classes. Had few ideas on hiw to fix this but none of them worked. At the end I've thought about using the advantage of JAR files being just archives and I've just deleted the java/xml/parsers/* using WinRAR.
I never thought it will be a working solution (especially that the contents were digitaly signed) but turns out just fine :)
You can achieve this same solution without resorting to manipulating the JAR contents by configuring your maven POM to use dependency exclusions - http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm quite sure I've tried that without any luck.
I'm not too familiar with java but the thing is that the B.jar file that I use does not have a dependency on some other jar... it's a part of it, one uber jar, all "dependency" classes are relocated to this one (I guess that this http://maven.apache.org/plugins/maven-shade-plugin/ is one way of getting such package). Are you sure this is going to work in my case?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.