1

I am integrating some jar files into a maven project as dependencies. The jar files have been given to me by some project partners. The jar files have dependencies between them. There is also a mix between publicly available jars such as org.apache.http.client and self-written code. The jars are included in an example application the eclipse-way i.e. using .classpath. Of course this is not directly portable to Maven. So I did the following:

  • I merged the jars into one using jar -xf / jar -cf.
  • I installed this jar using mvn install:install-file.
  • I added the dependency to my project's pom.xml

I recreated the example application using the Maven setup and everything seems to work. However, I want to use the library in a more complex situation, a Maven web application.

In this case the code from the jar seems to behave differently:

  • the http client flashes debugging messages to the log
  • there seems to be some confusion regarding (un-)marshalling of xml / json. This leads to an error message making it impossible for me to use the code.

The problem is that this error is very hard to pin down / fix. Since I don't have access to the source code of the jars I can't figure out what is happening and where. I guess that the problem is that there are different versions of packages involved.

Is there a way to make sure that symbols in the jars are always resolved using code in the jar itself or is there a better way to turn the jars into Maven dependencies?

Anders R. Bystrup
  • 14,996
  • 10
  • 58
  • 53
hfhc2
  • 3,705
  • 2
  • 22
  • 44

1 Answers1

1

Don't merge public and/or private dependencies into one uber-jar and deploy it to your repository. Instead, mavenize your project properly, write a pom.xml that references all the dependencies (including the private ones), deploy these to your repo and be happy ever after. You can always think up some group/artifact/version tuples for the private jars, and write POMs accordingly, referencing the inter-dependencies properly. Just keep it consistent!

Cheers,

Anders R. Bystrup
  • 14,996
  • 10
  • 58
  • 53
  • But then I would have to include dependencies into the poms, right? – hfhc2 May 19 '15 at 09:38
  • Ideally yes, but if you know you need them all, just reference them all in your main project. The trick is to have all the class and resource files available to the compiler and JVM runtime... – Anders R. Bystrup May 19 '15 at 09:40
  • But what if some jar depends on package-1.0 and my project depends on package-1.1. Which will be used? – hfhc2 May 19 '15 at 09:51
  • Then you should probably update your code to use 1.1 - welcome to Maven version hell :-) having said that, Maven does provide some very handy features for version handling - have a look at this great answer: http://stackoverflow.com/a/1172371/687514 – Anders R. Bystrup May 19 '15 at 09:58
  • But everything works if I create a single jar for a normal project. Is there a way to determine the problem with the other project? – hfhc2 May 19 '15 at 11:09