使用MAVEN手動建立web項目,mavenweb項目

來源:互聯網
上載者:User

使用MAVEN手動建立web項目,mavenweb項目

問題:如,使用maven建立webapp項目時,預設使用maven-archetype-webapp這個archetype,由於這個archetype比較古老,有如下缺點:

1. 預設產生的項目會報錯
The superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path    index.jsp    /demo/src/main/webapp    line 1    JSP Problem

2. 預設依賴jdk 1.5

3. Dynamic Web Module 版本為2.3

所以決定自己手動建立一個較新的webapp項目,這個新體現在以下幾個方面:

1. 依賴jdk 1.7

2. Dynamic Web Module 版本為3.0

 

過程如下

1. 勾選create a simple project (建立一個簡單的項目,跳過archetype選擇)

2. 正常填寫maven項目的資訊,點擊Finish

3. 產生的項目同樣會報錯,需要修改以下地方,首先時pom.xml檔案,如所示

<build>        <plugins>            <!-- 配置為jdk1.7 -->            <plugin>                <artifactId>maven-compiler-plugin</artifactId>                <version>3.3</version>                <configuration>                    <source>1.7</source>                    <target>1.7</target>                </configuration>            </plugin>        </plugins>    </build>    <dependencies>        <!-- servlet-api -->        <dependency>            <groupId>javax.servlet</groupId>            <artifactId>javax.servlet-api</artifactId>            <version>3.1.0</version>        </dependency>        <!-- jsp-api -->        <dependency>            <groupId>javax.servlet.jsp</groupId>            <artifactId>jsp-api</artifactId>            <version>2.2</version>        </dependency>        <!-- jstl 1.2 -->        <dependency>            <groupId>javax.servlet</groupId>            <artifactId>jstl</artifactId>            <version>1.2</version>        </dependency>        <!-- slf4j-log4j12 -->        <dependency>            <groupId>org.slf4j</groupId>            <artifactId>slf4j-log4j12</artifactId>            <version>1.7.7</version>        </dependency>    </dependecies>

4. 其次需要手動建立WEB-INF目錄和web.xml檔案,並更新web.xml為如下內容:

 

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

 

5. 接下來切換到Navigator視圖下,找到.settings目錄下的project facet的設定檔org.eclipse.wst.common.project.facet.core.xml,

將version更改為3.0然後更新項目 - <installed facet="jst.web" version="3.0"/>

6.最後更新maven項目,update project(Alt+F5)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.