IntelliJ Maven Project - Cannot resolve servlet in web.xml - spring

I've been looking at this problem for hours and haven't been able to see what went wrong.
My pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pages.crm</groupId>
<artifactId>pagescrm</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<!-- Making sure we get consistent versions -->
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.2.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<!--Java compiler plugin 1.6, 1.7 or 1.8?-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<verbose>true</verbose>
<source>1.8</source>
<target>1.8</target>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<!--Tomcat7 plugin -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Can anyone please help and identify why I keep getting a cannot resolve servlet mvc-dispatcher error?

Related

Cannot resolve symbol #Configuration in spring webmvc project

I am creating a Spring MVC project in Intellij and when I have created WebConfigclass, the #Configuration annotation is not recognised by Intellij and it gives "Cannot resolve symbol" error. Even though I have used "import org.springframework.context.annotation.Configuration" but it could not recognise "springframework" either. Can someone help me with this.
This is my pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>academy.learnprogramming</groupId>
<artifactId>Todo-list</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<logback.version>1.2.3</logback.version>
<spring.version>5.0.5.RELEASE</spring.version>
<java.version>8</java.version>
<annotation-api.version>1.3.2</annotation-api.version>
<servlet-api.version>3.1.0</servlet-api.version>
<!-- <lombok.version>1.18.12</lombok.version>-->
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>${annotation-api.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>edge</version>
<scope>system</scope>
<systemPath>${basedir}/libs/lombok-1.18.12.jar</systemPath>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet-api.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<target>${java.version}</target>
<source>${java.version}</source>
<release>${java.version}</release>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.6.7</version>
<configuration>
<container>
<containerId>tomcat9x</containerId>
<type>embedded</type>
</container>
<configuration>
<properties>
<cargo.servlet.port>8081</cargo.servlet.port>
</properties>
</configuration>
</configuration>
</plugin>
</plugins>
</build>
</project>
#Configuration belongs to module spring-context-${spring.version}. Make sure it appears among dependencies. Since in maven dependencies can be transitive, consider using:
mvn dependency:tree
to see which dependency brings the required jar.
When you're done, re-import the maven project into intelliJ so that the IDE will update its internal indices

Issue while setting up a spring maven project in eclipse

I want to set up a maven based spring project using eclipse. The following code block shows the content of my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyLearningProject</groupId>
<artifactId>MyLearningProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.0-alpha-1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>3.1.2.RELEASE</version>
</dependency>
</dependencies>
</build>
I'm getting the following error but don't know why:
cvc-complex-type.2.4.a: Invalid content was found starting with
element 'dependencies'.
Your pom is incorrect. You put <dependencies> to <build> section and that's why you get an error.
Try to move <dependencies> from <build> section, so your pom will be something like that:
<dependencies>
...
</dependencies>
<build>
...
</build>

ArtifactDescriptorException: Failed to read artifact descriptor for javax.servlet:servlet-api:jar:${as.default.javax.servlet.version}

I am using maven with my multi module project. I am not able to solve the error.
The error is given below :
Description Resource Path Location Type
ArtifactDescriptorException: Failed to read artifact descriptor for javax.servlet:servlet-api:jar:${as.default.javax.servlet.version}: ArtifactResolutionException: Failure to transfer javax.servlet:servlet-api:pom:${as.default.javax.servlet.version} from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact javax.servlet:servlet-api:pom:${as.default.javax.servlet.version} from/to central (http://repo.maven.apache.org/maven2): Illegal character in path at index 63: http://repo.maven.apache.org/maven2/javax/servlet/servlet-api/${as.default.javax.servlet.version}/servlet-api-${as.default.javax.servlet.version}.pom pom.xml /kern-web-proxy line 1 Maven Dependency Problem
I am just a beginner in maven so any help is valuable for me.
here is pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>kern</artifactId>
<groupId>com.appamsoft.as</groupId>
<version>0.1-SNAPSHOT</version>
</parent>
<groupId>com.appamsoft.as.kern</groupId>
<artifactId>kern-web-proxy</artifactId>
<!-- <version>0.1-SNAPSHOT</version> -->
<packaging>war</packaging>
<name>kern-web-proxy</name>
<dependencies>
<dependency>
<groupId>com.appamsoft.as.kern</groupId>
<artifactId>kern-core</artifactId>
<version>0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${as.default.springframework.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${as.default.javax.servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${as.default.javax.servlet.jsp.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${as.default.slf4j.version}</version>
</dependency>
<!-- <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</dependency>
-->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${as.default.log4j.version}</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${as.default.java.version}</source>
<target>${as.default.java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.5</version>
<configuration>
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>7.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
The screenshot of the multi module maven project is as follows:
And the top most pom of as project is given below:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.appamsoft</groupId>
<artifactId>as</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>as</name>
<modules>
<module>tools</module>
<module>kern</module>
</modules>
<properties>
<as.default.java.version>1.7</as.default.java.version>
<as.default.junit.version>4.8.2</as.default.junit.version>
<as.default.slf4j.version>1.6.6</as.default.slf4j.version>
<as.default.log4j.version>1.2.16</as.default.log4j.version>
<as.default.javax.servlet.version>2.5</as.default.javax.servlet.version>
<as.default.javax.servlet.jsp.version>2.1</as.default.javax.servlet.jsp.version>
<as.default.springframework.version>4.0.3.RELEASE</as.default.springframework.version>
<as.default.hibernate.version>3.5.0-Final</as.default.hibernate.version>
<as.default.camel.version>2.9.4</as.default.camel.version>
<as.default.activemq.version>5.6.0</as.default.activemq.version>
<project.build.maven.compiler.plugin.version>2.3.2</project.build.maven.compiler.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${as.default.slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${as.default.slf4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>${as.default.log4j.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${as.default.junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${as.default.javax.servlet.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>${as.default.javax.servlet.jsp.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Your parent section of the kern-web-proxy should be:
<parent>
<groupId>com.appamsoft</groupId>
<artifactId>as</artifactId>
<version>0.1-SNAPSHOT</version>
</parent>
or else it cannot resolve the properties. However, your parent's coordinates are resolving to something, most likely an older version, or else you would be getting another error (something along the lines of "non-resolvable parent").
The assumes that the parent POM is available one directory above kern-web-proxy. If that is not the case, you need to add adjust your parent section with a <relativePath> tag:
<parent>
<groupId>com.appamsoft</groupId>
<artifactId>as</artifactId>
<version>0.1-SNAPSHOT</version>
<!-- This should point to your parent POM if is not located at '..' -->
<relativePath>../..</relativePath>
</parent>
First i looked in local repo (.m2) there is name mismatch of jar's which were being used by me in kern-web-proxy pom.xml. So, I matched the jar's name as well as version number to local repo jar's. Then i got the solution of this error.

Spring Maven - ClassNotFound for DispatcherServlet

I am trying to start a web-app with Spring framework, and I am using maven to get the depepndent jars.
I use Tomcat 7.0.39
I have configured Eclipse to include all te maven dependencies into the WEB-INF/lib folder.
So, in my war, i do see all the jars. But still I get the ClassNotFound Exception for DispatcherServlet.
Here is the server log:
SEVERE: Servlet /bookRental threw load() exception
java.lang.ClassNotFoundException: com.springframework.web.servlet.DispatcherServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1713)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1558)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:527)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:137)
The following is my pom.xml file :
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>bookRental</groupId>
<artifactId>bookRental</artifactId>
<version>0.1</version>
<packaging>war</packaging>
<name>bookRental</name>
<description>an e-rental zone to share books</description>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>4.0.0.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>test</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>tomcat-maven-plugin</artifactId>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>mytomcat</server>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
You've used the wrong package name, com... instead of org..., try:
org.springframework.web.servlet.DispatcherServlet

Output directory for maven-bundle-plugin

I have this POM file which generates osgi bundle:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>test</artifactId>
<name>test</name>
<description>Module test</description>
<packaging>bundle</packaging>
<version>4.0</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>5.0.0</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>*</Import-Package>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
</instructions>
<outputDirectory>${user.home}/bbbblx</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
For some reason I cannot configure the plugin to generate the output bundle into the <outputDirectory>${user.home}/bbbblx</outputDirectory> directory.
There is no bbbblx directory in my home directory.
Can you help me to fix this issue?
You should use <buildDirectory>${user.home}/bbbblx</buildDirectory> instead of <outputDirectory>${user.home}/bbbblx</outputDirectory>.
I had the same problem and the fix mentioned above did the trick for me!

Resources