How to handle conflicting dependencies in Java (EE)

元气小坏坏 提交于 2019-12-10 15:49:16

问题


I'm developing an enterprise application on Java EE 6 platform. The IDE is NetBeans 7.2 and the application server is GlassFish 3.1.2.2.

The business logic has to use a library (HBase-RDF to be specific) to handle some tasks in its core. The original HBase-RDF code depends on many packages of which I believe their newer versions are already used by Glassfish. For instance, I can see javax.xml, javax.activation, com.sun.jersey and similar packages already included in the jar files.

Although I had previously developed not-so-trivial Java EE applications in the past, I have faced countless headaches developing the application which may or may not be related to this. From what I had read on the web, including dozens of stackoverflow questions and bug tracking systems, I guess I may be able to get rid of some of those headaches if I can package the original library (HBase-RDF) with all its dependencies as a whole jar file and prevent them being included directly in the project.

My first question is, am I right about the cause of the problems? Can this be the source of my problems? I guess the answer would be yes, because I have already solved one of my problems by removing JAXB and Xerces jars from the classpath and fortunately those portions of the Hbase-RDF I have to work with does not engage them.

And the second question is, in case that I'm right about the previous question, how can I do this? How can I restrict these libraries to be used only by one library (Hbase-RDF)?


NOTE: It may be useful to say that the build process finishes without any problems, but I face two major problems deploying and running the project. First, the application deploys successfully on my local Glassfish instance which is installed alongside netbeans, but the same .ear package fails to deploy on another same-version instance and the server.log file does not contain anything helpful for finding the cause of the problem. The error is very similar to this but the proposed solutions don't work. The second problem is very similar to this and again, I have tried every single proposed solution with no luck. It's interesting to see that the web service inside the web module calls the EJB successfully, but the JSF facelet index.html fails to run.


回答1:


I am not really sure if your concern is about the build process or the deployment.
Because for deployment, if you have a library that is dependent on a different version of a library you already deploy this is impossible to work without resorting to OSGi (can not have both versions of the library with the same classloader).
Have you tried completely removing the dependent libraries and only use the newer versions.
If your only dependencies are for JAXB and the xml package of java you might be lucky



来源:https://stackoverflow.com/questions/12185894/how-to-handle-conflicting-dependencies-in-java-ee

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!