3

i followed this spring-mvc-tutorial using eclipse, but after i call Maven / Update Projects my WEB-INF/lib directory remains empty.

this is how my project explorer looks:

enter image description here

i also see no mistake in my Deployment Assembly settings:

enter image description here

this is the pom.xml file i use:

<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>CrunchifySpringMVCTutorial</groupId>
<artifactId>CrunchifySpringMVCTutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-aop</artifactId>
        <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.2.0.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.2.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies> 
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <warSourceDirectory>WebContent</warSourceDirectory>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
    </plugins>
</build>

i even switched to a new workspace as suggested in this link, but nothing helped

EDIT: when i start the server i get the error: java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet

Community
  • 1
  • 1
richard
  • 724
  • 2
  • 14
  • 36

2 Answers2

5

Eclipse virtually hides the files from the view that displays the WEB-INF/lib folder in a Maven-managed Dynamic Web-Project project. As your first screenshot indicates, the "Maven Dependencies" library entry has been successfully added to your classpath in the background by Eclipse - it contains every dependency referenced in your pom.xml.

The intention behind this behavior for that is/might be: You - as a developer - are not supposed to copy any .jar files manually to WEB-INF/lib, cause that way you would kind of cheat around the idea behind a (Maven-) managed project.

In a certain way, this makes sense as Maven performs any dependency management for you and thus resolves and "bundles" any third-party (or your own) artifacts.

If you run a mvn with the goals clean package (or even: clean install) it will produce a .war file for you in the "target" folder of your project. If you extract that .war file you should find a WEB-INF/lib folder that contains all dependencies bundled into your deployable artifact.

MWiesner
  • 8,868
  • 11
  • 36
  • 70
  • so do you have any idea why i get this exception when i start the server? java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet – richard Aug 01 '15 at 11:36
  • you could try: remove your web-application from the configured Tomcat8 server completely, redeploy after (!) a full build via Maven's "clean install" goals - still, it is hard to say what piece is missing in your setup. At least, the "empty" view of the WEB-INF/lib folder is explainable to me. – MWiesner Aug 01 '15 at 11:43
  • Did you find a solution to this? I have the exact same problem of java.lang.ClassNotFoundException: org.springframework.web.servlet.DispatcherServlet – user2689782 Jan 26 '16 at 14:43
2

I think it is correct.

Libraries are copied into target after build, not into project itself.

Also Step 8 in the tutorial you pasted shows the same (empty lib folder)

libik
  • 22,239
  • 9
  • 44
  • 87