Dynamic Web Module 3.0 — 3.1

前端 未结 9 1874
谎友^
谎友^ 2020-12-07 13:47

I have a mavenized codebased configured Spring 3.2.4 web app. When I build the app with Maven/pom.xml first I got an error that web.xml is missing. first I tried to create

相关标签:
9条回答
  • 2020-12-07 13:51

    Open Eclipse project properties, in Project Facets unselect "Dynamic Web Module",... Click OK Maven -> Update project

    0 讨论(0)
  • 2020-12-07 13:53

    I had similar troubles in eclipse and the only way to fix it for me was to

    • Remove the web module
    • Apply
    • Change the module version
    • Add the module
    • Configure (Further configuration available link at the bottom of the dialog)
    • Apply

    Just make sure you configure the web module before applying it as by default it will look for your web files in /WebContent/ and this is not what Maven project structure should be.

    EDIT:

    Here is a second way in case nothing else helps

    • Exit eclipse, go to your project in the file system, then to .settings folder.
    • Open the org.eclipse.wst.common.project.facet.core.xml , make backup, and remove the web module entry.
    • You can also modify the web module version there, but again, no guarantees.
    0 讨论(0)
  • 2020-12-07 13:56

    If you want to use version 3.1 you need to use the following schema:

    • http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd

    Note that 3.0 and 3.1 are different: in 3.1 there's no Sun mentioned, so simply changing 3_0.xsd to 3_1.xsd won't work.

    This is how it should look like:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee" 
             xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
             version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
    
    </web-app>
    

    Also, make sure you're depending on the latest versions in your pom.xml. That is,

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            ...
        </configuration>
    </plugin>
    

    and

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

    Finally, you should compile with Java 7 or 8:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
        </configuration>
    </plugin>
    
    0 讨论(0)
  • 2020-12-07 14:04

    I was running on Win7, Tomcat7 with maven-pom setup on Eclipse Mars with maven project enabled. On a NOT running server I only had to change from 3.1 to 3.0 on this screen:

    For me it was important to have Dynamic Web Module disabled! Then change the version and then enable Dynamic Web Module again.

    0 讨论(0)
  • 2020-12-07 14:05

    In a specific case the issue is due to the maven-archetype-webapp which is released for a dynamic webapp, faceted to the ver.2.5 (see the produced web.xml and the related xsd) and it's related to eclipse. When you try to change the project facet to dynamic webapp > 2.5 the src folder structure will syntactically change (the 2.5 is different from 3.1), but not fisically.

    This is why you will face in a null pointer exception if you apply to the changes.

    To solve it you have to set from the project facets configuration the Default configuration. Apply the changes, then going into the Java Build Path you have to remove the /src folder and create the /src/main/java folder at least (it's also required /src/main/resources and /src/test/java to be compliant) re-change into the required configuration you desire (3.0, 3.1) and then do apply.

    0 讨论(0)
  • 2020-12-07 14:07
    1. Go to Workspace location
    2. select your project folder
    3. .setting folder
    4. edit "org.eclipse.wst.common.project.facet.core"
    5. change installed facet="jst.web" version="3.0"
    0 讨论(0)
提交回复
热议问题