maven建立webapp項目

來源:互聯網
上載者:User

標籤:ja

一、Eclipse配置

1、eclipse整合使用者自己安裝的jdk

2、eclipse整合使用者自己安裝的maven

3、eclipse整合使用者自己安裝的tomcat

4、去掉spell

5、修改字型 小四



二、maven建立webapp項目


new-->other-->maven project->use default workspace location(選擇工作目錄即可,不必命名專案檔夾)-->

maven-archetype-webapp-->定義artifactId,maven會根據artifactId在工作目錄建立一個檔案夾來存放項目




1、解決jsp-api和servlet-api相關jar報不在classpath路徑,導致servlet和jsp報錯的問題

項目-右鍵屬性-->project Facts-->Runtimes(右邊),選中配置的Tomcat,在Ecipse-->屬性-->Server中配置使用者自己的Tomcat



2、開發JavaEE項目,用JAVAEE視圖,方便尋找web.xml和jsp檔案,在Deployed Resources中可以方便尋找


3、更改web.xml,jsp模板,添加jstl依賴,更改junit版本

<dependencies>

    <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

      <version>4.12</version>

      <scope>test</scope>

    </dependency>

    

      

     <dependency>

      <groupId>javax.servlet</groupId>

      <artifactId>jstl</artifactId>

      <version>1.2</version>

    </dependency>

  </dependencies>



jsp頁面模版

  

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title></title>

</head>

<body>

<form action="${pageContext.request.contextPath }/#" method="post">

</form>

</body>

</html>




web.xml模板



<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" 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">

    

    

</web-app>



4、建立src目錄

定位到項目的src目錄,在main檔案夾下面建立java目錄,在src下面建立test/java,test/resources目錄

右鍵項目屬性,java Build path,勾選test/resources,並調整各個目錄的顯示順序。



5、將maven項目的module轉為為2.5


1、filters,不要過濾.resources檔案

.settings檔案夾

org.eclipse.wst.common.component.xml ---> project-version="1.6.0">

org.eclipse.wst.common.project.facet.core.xml  -->installed facet="jst.web" version="2.5"/>


6、匯入各類主題模板

http://eclipsecolorthemes.org/


7、在eclipse中整合tomcat,部署項目



8、maven自動發布項目到Tomcat



本文出自 “小魚的部落格” 部落格,謝絕轉載!

maven建立webapp項目

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.