Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Different version of jars in my tomcat/lib on building project  RSS feed

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On building my project, I get three versions of the freemarker jar and two versions of ognl jar. Because of this, I get weird javax/mail/MessagingException while server startup, which I am sure (for some reason) is because of the duplicate versions of multiple jars. For example, in my pom.xml, I only have freemarker-2.3.23, but on building my project with it, I also get freemarker-2.3.15 and freemarker-2.3.19 versions in my server/webapps/ROOT/WEB-INF/lib folder. These two versions are not at all mentioned in my pom.xml for the project. How can I make sure I don't get those older versions on building my project?
 
Rancher
Posts: 3767
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use your IDE to see what the dependencies are.  I think they all have a way of seeing where various jar files come from.
These other versions will have been brought in as dependencies for some other jar.

Then you need to figure out what version you actually need.
 
Akhil Ranjan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The two projects my project depends on do not have any version of these dependencies in their pom.xml :|
 
Dave Tolls
Rancher
Posts: 3767
40
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked in the IDE (or the command line, as I think there's a command to get the full dependency list produced)?

For example, if I open a pom file in Eclipse one of the tabs available is the Dependency Hierarchy, which will show me where everything has come from.

If the extra jar files are coming from a Maven build then they will appear here.
 
Bartender
Posts: 19996
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maven builds should not be pulling in multiple versions of the same jar. That's part of what Maven is for. I'd suspect that your IDE is ramming in extra JARs that it's getting from your IDE build properties somehow.

Maven has utilities that can list what jar and version dependencies exist for a project. The Eclipse Maven plugin can even display these dependencies graphically.
 
Saloon Keeper
Posts: 5052
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:Maven builds should not be pulling in multiple versions of the same jar. That's part of what Maven is for.


... to be more precise: Maven will happily pull in multiple different versions of a jar file, unless instructed not to do so. That's what exclusions are for: https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html


The command mvn dependency:tree will show all the dependencies of your project.
 
Tim Holloway
Bartender
Posts: 19996
95
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:
... to be more precise: Maven will happily pull in multiple different versions of a jar file, unless instructed not to do so. That's what exclusions are for: https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html



Actually, no. If you'll notice on that page, the exclusion elements didn't specify version IDs, only group and artefact IDs. The exclusion clause is to block transitive dependency fetching. That is, B depends on B, B depends on C, but you don't actually want C to be sucked into the process, irrespective of the version of C.

The dependency:tree goal, on the other hand, can be invaluable. The Maven equivalent of "DLL Hell" is when you have conflicting versions in dependencies, since one will win and the rest - unless memory fails me - will be ignored and the results are not good. So not infrequently I've had to use the dependency:tree to walk back through my explicit dependencies versions until both they and the transitive dependencies agreed on their versions.
 
Tim Moores
Saloon Keeper
Posts: 5052
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Holloway wrote:the exclusion elements didn't specify version IDs, only group and artefact IDs.


Right. And one of those dependencies will pull in the unwanted jar file. So you exclude it :-)
 
Sheriff
Posts: 21466
97
Chrome Eclipse IDE Java Spring Ubuntu VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've never seen Maven add two versions of a dependency. There has always been one "winner" which causes other versions to be ignored.
 
Akhil Ranjan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:Have you checked in the IDE (or the command line, as I think there's a command to get the full dependency list produced)?

For example, if I open a pom file in Eclipse one of the tabs available is the Dependency Hierarchy, which will show me where everything has come from.

If the extra jar files are coming from a Maven build then they will appear here.



I thoroughly checked the Dependency hierarchy for my project and also for the 2 projects that my project depends on, but I'm still stuck
 
Dave Tolls
Rancher
Posts: 3767
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK.
You shouldn't need to check the other two projects if they are Maven dependencies as their dependencies will appear in the hierarchy of the project you are having an issue with.

How do you build your project?
 
Akhil Ranjan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:OK.
You shouldn't need to check the other two projects if they are Maven dependencies as their dependencies will appear in the hierarchy of the project you are having an issue with.

How do you build your project?



Thank you. I really appreciate all the help. I finally figured what's happening. Somehow I'm getting those jars from struts2-core version 2.3.14.3. But I've version 2.3.32 in my pom. What I need to do is omit everything I am getting  from v2.3.14.3. Can you help me with that?

I'm building using Jenkins tool/application.
 
Dave Tolls
Rancher
Posts: 3767
40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would have to hand you over to someone who has more experience setting these things up.
 
Tim Moores
Saloon Keeper
Posts: 5052
135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Can you help me with that?


Check the link I posted earlier.
 
Akhil Ranjan
Greenhorn
Posts: 17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:

Can you help me with that?


Check the link I posted earlier.



Thank you. I looked into it and I think I finally have a hang of the issue. I'm getting the unnecessary jars like older version of xwork-core, ognl and freemarker from struts2-core v2.3.14.3 which is not in my pom. My pom has struts2-core v2.3.32 which is also fetching newer version of those jars, and this is causing the conflict. What I want is to not have those jars from v2.3.14.3. What I tried doing was explicitly have v2.3.14.3 in my pom along with v2.3.32 and use exclusion tags for those dependent jars (xwork-core, ognl etc) of the 2.3.14.3 dependency. I was able to get rid of the jars corresponding to that version (2.3.14.3), but the struts2-core jar of that version takes precedence over the newer version of struts2-core (2.3.32). If only I could have chosen struts2-core v2.3.32 jar over v2.3.14.3. The exclusion tags helped me in getting the correct version of xwork-core, ognl and freemarker (the version that is retrieved from struts2-core v2.3.32).
 
Akhil Ranjan
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I finally got the problem sorted. Thank you @Tim Moores & @Dev Tolls. Much appreciated
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!