Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing Dynamic Web Module version in Eclipse Maven Project

I'm trying to set up Dynamic Web Module 3.0 in order to support Java 6 development. I'm getting this error in my Problems tab of eclipse whenever I do Maven > Update Project.

Dynamic Web Module 3.1 requires Java 1.7 or newer.

It appears as though nothing is going wrong, but I must be missing something because I consistently receive this error.

Below is the contents of my .settings/org.eclipse.wst.common.project.facet.core.xml

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="jst.java"/>
  <fixed facet="jst.web"/>
  <installed facet="jst.java" version="1.6"/>
  <installed facet="jst.web" version="3.0"/>
</faceted-project>

In eclipse, my Java Compiler is set to 1.6 properly. In the Project Facets tab, Dynamic Web Module is specified as version 3.0 correctly, and Java also appears as 1.6 under Project Facets.

In my pom.xml file, I have also set the Java version accordingly:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>

As a side note, I should also mention that I am doing a pure-Java build with a WebApplicationInitializer and have no web.xml file.

Any help is greatly appreciated as I attempt to squash this seemingly irrelevant error message.

EDIT: added pom.xml contents

<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>net.XXXXX</groupId>
    <artifactId>XXXXX</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>XXXXX</name>
    <packaging>war</packaging>
    <url>http://maven.apache.org</url>

    <build>
        <finalName>XXXXX</finalName>

        <plugins>

            <!-- Source level should be 1.6 (not Maven default) for Java EE 6 projects -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <!-- When using xml-less approach, need to disable Maven's warning about 
                missing web.xml -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

        </plugins>
    </build>
    <dependencies>

        <!-- JUnit testing -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <!-- Spring Core -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>

        <!-- Spring MVC -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>

        <!-- Spring Context without commons-logging -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.0.2.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Spring Security core -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>3.2.1.RELEASE</version>
        </dependency>

        <!-- Spring Security config -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>3.2.1.RELEASE</version>
        </dependency>

        <!-- Spring Security web -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>3.2.1.RELEASE</version>
        </dependency>

        <!-- jcl-over-slf4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.6</version>
        </dependency>

        <!-- slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.6</version>
        </dependency>

        <!-- slf4j-log4j12 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.6</version>
        </dependency>

        <!-- log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- Need servlet API for compiling the classes. Not needed in runtime -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Required for xml-less configuration of Spring via @Configuration annotations -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>3.1</version>
        </dependency>

        <!-- Required for getting Spring working with Hibernate -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.4.Final</version>
        </dependency>

        <!-- For using JPA instead of "pure Hibernate" -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.4.Final</version>
        </dependency>

        <!-- DB connection pooling for production applications -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>20030825.184428</version>
        </dependency>

        <!-- Concrete JDBC driver for MySQL DB -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.29</version>
        </dependency>

        <!-- Add Taglib support -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

    </dependencies>

</project>
like image 888
Geoffrey Tucker Avatar asked Mar 14 '14 12:03

Geoffrey Tucker


People also ask

What is dynamic web module in eclipse?

Last updated : March 7, 2021. Dynamic web projects use server-side scripting, meaning each user request is processed differently by the server and render different outcomes based on parameters.


2 Answers

In an our project, we add to change the web.xml root element's declaration, changing from:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">

to:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5" >

Probably Eclipse were expecting it as satisfying a different Servlet version spec. In our case too, we had neither compile nor runtime problems.

EDIT: In your case, where you were not using a web.xml file, there was the following pom's dependency which probably was confusing Eclipse's maven plugin:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

Change it to "3.0.1". (It turns out that WebApplicationInitializer requires "Servlet 3.0+ environments" and not 3.1+)

like image 61
robermann Avatar answered Oct 26 '22 03:10

robermann


you can add this to the pom.xml:

<build>
    <plugins>
        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>
    </plugins>
</build>

Works in Spring STS 3.6.3 :)

edit:

source: http://crunchify.com/how-to-solve-dynamic-web-module-3-1-requires-java-1-7-or-newer-in-eclipse/

like image 21
Enrique San Martín Avatar answered Oct 26 '22 01:10

Enrique San Martín