How tomcat-servlet-api is linked to servlet-api? - java

On a online course, I have this following project's pom's piece:
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>7.0.30</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
This project is supposed to run on Tomcat7, and it does. I noticed it excluded servlet-api from jstl-api and jstl-impl and it uses tomcat-servlet-api as provided. This are my Tomcat's libs:
Since it just have servlet-api.jar, where does the mapping between this two different names occur?

wherever servlet-api classes are used, the servlet-api classes included in the tomcat-servlet-api are used instead. the tomcat-servlet-api wraps the servlet-api classes.

Related

Object Mapper - YAMLFactory - exception due to missing _createContentReference method

I'm using the latest 2.13.0 version of jackson, and when I try to parse a YAML file, I'm getting this exception
java.lang.NoSuchMethodError: 'com.fasterxml.jackson.core.io.ContentReference com.fasterxml.jackson.dataformat.yaml.YAMLFactory._createContentReference(java.lang.Object)'
What could be the issue?
The dependencies that I've included are jackson-core, jackson-databind and jackson-dataformat-yaml - all 2.13.0
No such method error in most cases means that you have have 2 dependencies that are the same but with different versions, however the application is loading the version that does not have this method in it,
The reference to this _createContentReference exists in YAMLFactory in jackson-dataformat-yaml.jar
The actual _createContentReference implementation exists in com.fasterxml.jackson.core.JsonFactory which exists jackson-core.2.13.0.
In your case, you probably have another jackson-core.jar with an older version as part of your indirect dependencies.
You can see mvn dependency:tree or your IDE (Such as Eclipse allows you to search for dependency by name, and it returns all that match, including their versions)
Thanks.
It helped me to exclude jackson-dataformat-yaml version 2.13.1 from quarkus-smallrye-openapi and include 2.12.3 . Like this :
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
<exclusions>
<exclusion>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.12.3</version>
</dependency>
The same problem I also faced. My environment is -
Wildfly version - 26.1.1-Final
Spring boot - 2.7.8
The issue is coming because Wildfly has the same version API already added as module and the same set of jackson* series jars are going thourgh spring boot hence on runtime it is creating issue.
Solution - all jackson* jar under spring-boot pom.xml add into exclusion list and separtly added dependencies with scope provied. My modified pom.xml is as below -
<properties>
<spring.boot.version>2.7.8</spring.boot.version>
<jackson.version>2.13.4</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<!-- Exclusion list -->
<exclusion>
<artifactId>jackson-datatype-jdk8</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-datatype-jsr310</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- added dependency with provided scope -->
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>jackson-datatype-jdk8</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>jackson-datatype-jsr310</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>${jackson.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

Maven package does not exist

I have been trying to re-compile an application that uses Hadoop and Spark from the Cloudera distribution 5.4.0 with Maven, doing a mvn clean package command, and I keep getting the following error:
[ERROR]
/.../src/main/java/org/apache/sysml/runtime/instructions/spark/functions/SparkListener.java:[35,33]
package org.apache.spark.ui.scope does not exist
These are the relevant parts of the pom.xml file, with properties, dependencies and repositories.
<properties>
<hadoop.version>2.6.0-cdh5.4.0</hadoop.version>
<spark.version>1.3.0-cdh5.4.0</spark.version>
<antlr.version>4.3</antlr.version>
<!-- OS-specific JVM arguments for running integration tests -->
<integrationTestExtraJVMArgs />
</properties>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>${spark.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-mllib_2.10</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-assembly_2.10</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-yarn_2.10</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<!-- To support dataframe in mlcontext -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<!-- Adding Gauva version 14.0.1 to workaround conflict between spark and hadoop dependency -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-client</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-app</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-jobclient</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>1.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.wink</groupId>
<artifactId>wink-json4j</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
<version>${antlr.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>antlr-runtime</artifactId>
<groupId>org.antlr</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>${antlr.version}</version>
</dependency>
<!-- Libraries for yarn integration -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-api</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-common</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-yarn-client</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-mapreduce-client-common</artifactId>
<version>${hadoop.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>cloudera</id>
<url>https://repository.cloudera.com/artifactory/cloudera-repos</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
Apparently, the inclusion of dependency spark-core should include the package org.apache.spark.ui.scope.
Does anyone know what can be the cause of this problem and how to solve it?
Thanks!

Exclude a maven dependecie from a derived pom

I'm using Apache Maven 3.1.1
In my parent pom there is a dependencie defined as follows:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>1.2_09</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
The issue is I don't want to include that dependencie in one of my derived poms. I tried the following:
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
<exclusions>
<exclusion>
<groupId>javax.faces</groupId>
<artifactId>jsf-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.0.6</version>
<scope>compile</scope>
<type>jar</type>
</dependency>
But I got both jsf-impl-1.2_09.jar and jsf-impl-2.0.6.jar jars instead of jsf-impl-2.0.6.jar only. Is there a way to fix that?

Maven: How To Keep A Dependency Out?

I'm new to Maven. I recently learned it to solve some dependency issues I'm having with a Java and Spring WebApp. I've been trying maven out on a small sample webapp. The webapp uses JSTL tags. I found it necessary to put these tags in pom.xml:
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2-rev-1</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
</dependency>
These get 2 jars that I need:
jstl-api-1.2-rev-1.jar
jstl-impl-1.2.jar
BUT it also includes THIS jar in my WEB-INF/lib, the inclusion of which causes all sorts of errors when I try to run it in Tomcat 7:
jsp-api-2.1.jar
Is there a way I can rewrite my dependency tags to leave jsp-api-2.1.jar out of my WEB-INF/lib ?
Thanks
Fixed. Thanks Guys. FWIW, this is how I changed the dependency tags for the JSTL to not put the JSP-API jar in my WEB-INF lib:
<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2-rev-1</version>
<exclusions>
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
<exclusions>
<exclusion>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
</exclusion>
</exclusions>
</dependency>
I was able to find the groupID and artifactID at this site
https://repository.sonatype.org/index.html#welcome
Have exclusions section, similar to the one below.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.6.ga</version>
<exclusions>
<exclusion>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
</exclusion>
</exclusions>
</dependency>
In your case, one (or both) of the dependencies you add include the one that you do not need. Find which one, and add the exclusion section.
Change the scope to 'provided'. EG:
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>jstl-impl</artifactId>
<version>1.2</version>
<scope>provided</scope>
</dependency>
The provided scope ensures that jar is available to the compiler, but assumes that it will be 'provided' at runtime when the code is run. In your cast, it is provided by Tomcat.

What is correct version or jackson for spring?

I am using jackson converter (MappingJacksonHttpMessageConverter) to consume and produce json data from spring controller. But while invoking controller throws following exception.
Caused by: java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.isConcrete()Z
at org.codehaus.jackson.map.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:80)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createDeserializer(StdDeserializerProvider.java:266)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createAndCacheValueDeserializer(StdDeserializerProvider.java:198)
at org.codehaus.jackson.map.deser.StdDeserializerProvider.hasValueDeserializerFor(StdDeserializerProvider.java:152)
at org.codehaus.jackson.map.ObjectMapper.canDeserialize(ObjectMapper.java:829)
My code:
Spring bean file:
abc.CartType
abc.CartResponseType
pom file (snippets only)
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compileSource>1.5</compileSource>
<org.springframework.version>3.0.2.RELEASE</org.springframework.version>
<jboss.server.name>network-epro</jboss.server.name>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>sso</groupId>
<artifactId>casclient</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.1.5.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib-ext-spring</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>xpp</groupId>
<artifactId>xpp</artifactId>
<version>2.3.0</version>
</dependency>
<!-- http://code.google.com/p/jsonp-java/ -->
<dependency>
<groupId>org.jsonp</groupId>
<artifactId>jsonp</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>email</groupId>
<artifactId>email-client</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.2.ga</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!--
Jboss client dependancy.
-->
<dependency>
<groupId>jboss</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.2.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-oxm-tiger</artifactId>
<version>1.5.9</version>
</dependency>
I can see in spring-web pom file jackson version is mentioned as 1.4.2 and same I have used still it is throwing exception regarding method not found. Am I using correct version?
You seem to be missing the jackson-core dependency. You need that as well as jackson-mapper.
The 1.4.x version should be fine, although it shouldn't hurt to upgrade it to something more recent.
I think you have differing versions between Jackson core and mapper jars (former has streaming parser/generator; latter data binding). It is hard to ensure that transitive dependencies have compatible versions -- while multiple Jackson versions work just fine with Spring (and most other frameworks), versions of mapper and core have bit stricter dependencies.
Specifically: version of core should not be much older than version of mapper, as newer mapper versions depend on new features in core. Reverse matters less; so it is generally fine to have older mapper version, newer core (core also changes at much slower pace at this point).
I found the problem.
Use Jacson version 1.4.2 should not have problem and as StaxMan suggested core is dependably for mapper so it will be automatically resolved no need to declare it explicitly.
Now coming back to problem. It is classpath issue within jboss. I have two web application deployed in same server one with dependency on jacson versioin 1.1.1 and other one with 1.4.2. I dont yet have solution, So I have posted another question related to Jboss.

Categories

Resources