Ant + Ivy: Resolving spring dependencies - java

In my spring webapplication I am trying to get my dependencies resolved by Ivy. So here's my setup:
ivy.xml: http://pastebin.com/sDykaRn4
ivysettings.xml: http://pastebin.com/NmQsdG2m
build.xml: http://pastebin.com/Z5Z2XmmW
web.xml: http://pastebin.com/r06wbLr5
/WEB-INF/dispatcher-servlet.xml: http://pastebin.com/F4bdPyr4
My dependencies are getting well resolved by Ivy into my .ivy2/cache folder and then copied to lib.dir. The report gives me the following conflicts:
---------------------------------------------------------------------
| | modules || artifacts |
| conf | number| search|dwnlded|evicted|| number|dwnlded|
---------------------------------------------------------------------
| compile | 257 | 223 | 221 | 50 || 204 | 204 |
| runtime | 248 | 215 | 213 | 48 || 197 | 197 |
| test | 249 | 216 | 214 | 48 || 198 | 198 |
---------------------------------------------------------------------
Module Selected Evicted
xercesImpl by xerces 2.10.0 2.8.1 2.8.0
xml-apis by xml-apis 1.4.01 1.3.02 1.3.04 1.3.03
jaxen by jaxen 1.1.4 1.1.1
jsch by com.jcraft 0.1.51 0.1.42
commons-io by commons-io 1.4 1.3.2 1.3
xalan by xalan 2.7.1 2.7.0
slf4j-api by org.slf4j 1.7.12 1.5.3 1.5.8 1.6.1
backport-util-concurrent by backport-util-concurrent 3.1 3.0
poi by org.apache.poi 3.12 3.0.2-FINAL
commons-codec by commons-codec 1.9 1.6 1.2
commons-lang by commons-lang 2.6 2.3 2.4 2.1
tiles-jsp by org.apache.tiles 2.1.2 3.0.1
tiles-servlet by org.apache.tiles 2.1.2 3.0.1
tiles-core by org.apache.tiles 2.1.2 3.0.1
tiles-api by org.apache.tiles 3.0.1 2.1.2
spring-web by org.springframework 3.2.4.RELEASE 2.5.6
jackson-mapper-asl by org.codehaus.jackson 1.4.2 1.5.2
httpcore by org.apache.httpcomponents 4.2 4.0-beta1
servlet-api by javax.servlet 2.5 2.4 2.3
activation by javax.activation 1.1 1.0.2
jcommon by jfree 1.0.16 1.0.0
commons-logging by commons-logging 1.2 1.1.1 1.0 1.1 1.1.3 1.0.4 1.0.3
commons-digester by commons-digester 2.1 1.8 1.8.1 2.0
commons-collections by commons-collections 20040616 2.0 3.2.1 3.2 3.1
commons-beanutils by commons-beanutils 1.7.0 1.8.3
itext by com.lowagie 2.1.7 [1.02b,)
joda-time by joda-time 2.1 1.6.2
log4j by log4j 1.2.17 1.2.16 1.2.14
When I try to start my tomcat server in Eclipse, the server won't start (well, it does start, but with lots of Errors) and prints this log: http://pastebin.com/dtA6vFcK
My research on the org.springframework.beans.factory.BeanCreationException suggested that I am using multiple versions of spring. But as you can see in my ivy file and report, I only use 3.2.4.RELEASE. And I don't see how any of those ivy conflicts would harm the startup of my spring application.
Here's a list of the jars in my lib.dir: http://pastebin.com/01E2CQrx
Do you might see any problem...?
Thank you so much... really need your help on this one.

Related

Difference between "mvn dependency:tree" and http://repo.maven.org dependency details

In my project there is a Java Class which does:
import javax.activation.DataHandler;
My POM only has this dependency:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.5.0-b01</version>
</dependency>
Build (mvn clean install) is working, because:
mvn dependency:tree
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli)
[INFO] \- javax.mail:mail:jar:1.5.0-b01:compile
[INFO] \- javax.activation:activation:jar:1.1:compile
But why does
https://mvnrepository.com/artifact/javax.mail/mail/1.5.0-b01
and also
https://repo1.maven.org/maven2/javax/mail/mail/1.5.0-b01/mail-1.5.0-b01.pom
say there are no dependencies ???
Another question:
Why does javax.mail:mail:jar:1.5.0-b01 (from 2013) not depend on the latest javax.activation:activation:jar:1.1.1 (from 2009)?
Because mvnrepository has it wrong, "javax.mail:mail:jar:1.5.0-b01" version does have dependency to "javax.activation:activation:jar:1.1", it's in it's parent:
https://repo1.maven.org/maven2/com/sun/mail/all/1.5.0-b01/all-1.5.0-b01.pom
Don't depend on mvnrepository very much, the truth is always in pom files. Btw. javalibs shows you the dependency:
https://javalibs.com/artifact/javax.mail/javax.mail-api
Why the newest javax.mail version doesn't contain dependency to activation-api is probably due to transition to jakarta artifacts ... old javax dependencies cannot depend on new jakarta dependencies because Oracle said so ... :-( Newest javax.mail and activation artifacts are these:
https://javalibs.com/artifact/javax.mail/javax.mail-api
https://javalibs.com/artifact/jakarta.mail/jakarta.mail-api

Nosuchmethoderror:org.glassfish.jersey.internal.l10n.LocalizableMessageFactory

I m working with jersey2.29 and Spring 4 to develop a web application. The following are my dependencies.
When starting Tomcat server 8 server, it doesn't start and I get the following error
Caused by: java.lang.NoSuchMethodError: org.glassfish.jersey.internal.l10n.LocalizableMessageFactory.(Ljava/lang/String;Lorg/glassfish/jersey/internal/l10n/LocalizableMessageFactory$ResourceBundleSupplier;)V
at org.glassfish.jersey.server.spring.LocalizationMessages.(LocalizationMessages.java:19)
at org.glassfish.jersey.server.spring.SpringWebApplicationInitializer.onStartup(SpringWebApplicationInitializer.java:46)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5154)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 6 more
I tried adding all the latest jar files in WEB-INF/lib
You not have minimal dependency for jersey-spring4 which is Spring 4.3.8
org.springframework spring-aop 4.3.8.RELEASE jar Apache License, Version 2.0
org.springframework spring-beans 4.3.8.RELEASE jar Apache License, Version 2.0
org.springframework spring-core 4.3.8.RELEASE jar Apache License, Version 2.0
org.springframework spring-web 4.3.8.RELEASE jar Apache License, Version 2.0
You should use spring-jersey3 jar

How to print the version of a maven library dependency to console

Can someone help me on how to print the version of a library to the console? For example, my dependency in pom.xml is as follows:
<dependency>
<groupId>com.abc.client</groupId>
<artifactId>AbcClient</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>xyz</classifier>
</dependency>
And the exact library that is downloaded is "AbcClient-1.0-20171107.000833-111.jar". I want the full name of the library with its version to be printed to the console.
Example console output:
AbcClient-1.0-20171107.000833-111.jar
If you only want the dependency jar and its version then did you try Apache Maven Dependency Plugin?
https://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html
Sample Usage on one of my project
mvn dependency:tree | grep jackson-jaxrs-json-provider
[INFO] +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.8.8:provided
[INFO] | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.8.8:compile

Resolve duplicate versions of dependency

This has been very annoying. I have 2 projects, project A and B, B with dependency on A as a JAR file. So a 3rd library X in A has a dependency on another 3rd party library Y, the problem is maven resolves Y in project A to a version, but in project B to another version, like the following:
commons-beanutils:jar:1.9.2 vs. commons-beanutils:jar:1.8.0
And the version below is specified in project A:
net.sf.json-lib:json-lib:jar:jdk15:2.4
In the POM.xml of project B, there isn't really any explicitly specified version of dependencies.
In project A:
[INFO] +- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.9.2:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
In project B that only introduces the dependency on Y because of A:
[INFO] +- A.jar
[INFO] | +- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
The ideal solution is to only make changes in pom.xml in project B to solve the duplicate versions dependency hell. Any idea? Thanks!
Is it possible to make project B inherit dependencies from A.jar instead of introducing those of its own.
EDIT
In the end I found something that worked, so I'd just put it here in case someone may be facing the same problem later.
The key is to put the dependencies come with project A into exclusions, so maven won't just use the versions of libraries defined in project A, but work out a version based on the current context. Below is the example:
<dependency>
<groupId>com.wonderland</groupId>
<artifactId>project-a</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</exclusion>
<!-- ... everything else to be excluded -->
<exclusions>
</dependency>
Let me put the main points into an answer.
B is a war and depends on the jar A. So it inherits all the transitive dependencies of A.
net.sf.json-lib:json-lib:jar:jdk15:2.4:compile has actually a dependency on commons-beanutils:commons-beanutils:jar:1.8.0:compile (I looked that up). So your project B correctly resolves this dependency (and puts it into the war).
The tree of project A shows a dependency of commons-beanutils on version 1.9.2. This version number must have come from some other place inside project A. It may be a dependencyManagement, it may be some other dependency. Track down where the version 1.9.2 comes from and you know more.
In any case, the war will only contain the version 1.8.0 and not 1.9.2 as you can never have two artifacts with same groupId/artifactId in one war.

The method getDispatcherType() is undefined for the type HttpServletRequest

When I run my applicaiton from Eclipse it runs without any errors for servlet api 3.1.0 and 3.0.1.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
I use tomcat 8.0.21 for eclipse. I have set up tomcat8 on ubuntu machine which runs on tomcat 8.0.14 stable version.
Unfortunately, I get the following error message if I use servlet api 3.1.0. But it works for the older version 3.0.1.
root cause
org.apache.jasper.JasperException: Unable to compile class for JSP:
An error occurred at line: [50] in the generated java file: [/var/lib/tomcat8/work/Catalina/localhost/ROOT/org/apache/jsp/WEB_002dINF/view/templates/login_002dtemplate_jsp.java]
The method getDispatcherType() is undefined for the type HttpServletRequest
Stacktrace:
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:103)
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:199)
org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:450)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:336)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:323)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:564)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:357)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
Why do I get this error? How to fix this?
You're not supposed to provide Servlet API along with the web application archive if the target runtime already provides the API out the box. Tomcat as being a JSP/Servletcontainer already provides JSP, Servlet and EL APIs out the box. When you provide them along with your webapp anyway, then you may run into classloading conflicts caused by duplicate different versioned classes in the runtime classpath coming from both the webapp and the server.
Add <scope>provided</scope> to those dependencies already provided by the target runtime.
See also:
How do I import the javax.servlet API in my Eclipse project?
For Maven users there are several good answers here that you might want to check out.
I'm still in the dark ages, and am not using a dependency manager for my Tomcat project. If you're like me and have this issue, here's how I solved it: It seems tomcat provides the javax.servlet classes, so these don't need to be in your project's lib file. (I originally had the servlet-api-2.5.jar in my /WEB-INF/lib directory.) However you'll probably still need it to compile (I did), so you should move it to a location included in your java classpath. You may also need to tell your IDE where to look.
Hope that helps.
Method ServletRequest#getDispatcherType() was introduced to the Servlet Spec since version 3.0. The following error means that you are using an older version (e.g., 2.5) of javax.servlet-api in your application.
The method getDispatcherType() is undefined for the type HttpServletRequest
To solve this issue, you could follow the following two steps:
First of all, add <scope>provided</scope> to dependency javax.servlet-api
You should add <scope>provided</scope> to the dependency, because your Tomcat container will provide the dependency at runtime. And at the same time, ensure that you are using Tomcat 7 or higher, which supports Servlet Spec 3.0 or higher.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Second of all, exclude any older version of javax.servlet-api
You need to ensure that any older version (e.g., 2.5) of javax.servlet-api is not included transitively. You can use mvn dependency:tree to find out. See below an example:
$ mvn dependency:tree
...
[INFO] +- com.google.oauth-client:google-oauth-client-servlet:jar:1.20.0:compile
[INFO] | +- com.google.oauth-client:google-oauth-client:jar:1.20.0:compile
[INFO] | +- com.google.http-client:google-http-client-jdo:jar:1.20.0:compile
[INFO] | +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] | \- javax.jdo:jdo2-api:jar:2.3-eb:compile
[INFO] | \- javax.transaction:transaction-api:jar:1.1:compile
...
In this case, javax.servlet-api version 2.5 is included transitively by a dependency called google-oauth-client-servlet. We need to exclude it in pom.xml, like below:
<dependency>
<groupId>com.google.oauth-client</groupId>
<artifactId>google-oauth-client-servlet</artifactId>
<version>1.20.0</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
That's it.

Categories