這篇文章主要介紹Eclipse中如何使用Maven創(chuàng)建Java Web工程,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
Eclipse中使用Maven創(chuàng)建Java Web工程的實(shí)現(xiàn)方式
1)在Eclipse項(xiàng)目欄中右鍵單擊空白,New(或直接使用Ctrl+N快捷鍵) —— Other ——Maven Project。
2)選擇以webapp模板創(chuàng)建工程
3)填寫Group Id 、 Artifact Id 等信息。
groupId
定義了項(xiàng)目屬于哪個(gè)組,舉個(gè)例子,如果你的公司是mycom,有一個(gè)項(xiàng)目為myapp,那么groupId就應(yīng)該是com.mycom.myapp.
artifacted
定義了當(dāng)前maven項(xiàng)目在組中唯一的ID,比如,myapp-util,myapp-domain,myapp-web等。
version
指定了myapp項(xiàng)目的當(dāng)前版本,SNAPSHOT意為快照,說明該項(xiàng)目還處于開發(fā)中,是不穩(wěn)定的版本。
4)創(chuàng)建完成之后,有的電腦會提示Servelet相關(guān)的包沒有被導(dǎo)入。這個(gè)我們可以統(tǒng)一在POM.XML文件中統(tǒng)一去寫。pom.xml里面的依賴可以在http://mvnrepository.com/ 這個(gè)網(wǎng)站上去查找,該站點(diǎn)已經(jīng)幫你把依賴按格式寫好,十分方便。下面給出一份我以前做練手項(xiàng)目所用的pom.xml文件。
<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>org.seckill</groupId> <artifactId>seckill</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>seckill Maven Webapp</name> <url>http://maven.apache.org</url> <dependencies> <dependency> <!-- 使用junit4注解方式 --> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.11</version> <scope>test</scope> </dependency> <!-- 補(bǔ)全項(xiàng)目依賴 --> <!-- 1:日志 java日志:slf4,log4j,logback slf4j是 規(guī)范、接口 日志實(shí)現(xiàn):log4j、logback --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.12</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-core</artifactId> <version>1.1.1</version> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.1.1</version> </dependency> <!-- 實(shí)現(xiàn)slf4j接口并整合 --> <!-- 2:數(shù)據(jù)庫相關(guān)依賴 --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.35</version> <scope>runtime</scope> </dependency> <!-- 數(shù)據(jù)庫連接池 --> <dependency> <groupId>c3p0</groupId> <artifactId>c3p0</artifactId> <version>0.9.1.2</version> </dependency> <!-- DAO框架依賴:MyBatis依賴 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.3.0</version> </dependency> <!-- MyBatis自身實(shí)現(xiàn)的Spring整合依賴 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> <version>1.2.3</version> </dependency> <!-- 3:Servlet Web相關(guān)依賴 --> <dependency> <groupId>taglibs</groupId> <artifactId>standard</artifactId> <version>1.1.2</version> </dependency> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> <version>1.2</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>2.5.4</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> </dependency> <!-- 4:Spring依賴 --> <!-- 1)Spring核心依賴 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>4.1.7.RELEASE</version> </dependency> <!-- 2)Spring dao層 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <version>4.1.7.RELEASE</version> </dependency> <!-- 3)Spring web依賴 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>4.1.7.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>4.1.7.RELEASE</version> </dependency> <!-- 4)Spring test相關(guān)的依賴 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <version>4.1.7.RELEASE</version> </dependency> <!-- redis客戶端:Jedis --> <dependency> <groupId>redis.clients</groupId> <artifactId>jedis</artifactId> <version>2.7.3</version> </dependency> <!-- protostuff序列化 --> <dependency> <groupId>com.dyuproject.protostuff</groupId> <artifactId>protostuff-core</artifactId> <version>1.0.8</version> </dependency> <dependency> <groupId>com.dyuproject.protostuff</groupId> <artifactId>protostuff-runtime</artifactId> <version>1.0.8</version> </dependency> <!-- collections集合框架工具 --> <dependency> <groupId>commons-collections</groupId> <artifactId>commons-collections</artifactId> <version>3.2.1</version> </dependency> </dependencies> <build> <finalName>seckill</finalName> </build> </project>
5)注意web.xml中要開啟標(biāo)簽庫和EL表達(dá)式支持,要用2.3以上版本,所以把xml頭部的都改掉
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1" metadata-complete="true">
6)maven 項(xiàng)目的src/main/java 和 src/main/resources 都是項(xiàng)目根目錄(classpath:)。例如,想訪問src/main/resources 目錄下的mybatis-config.xml,它的路徑參數(shù)要寫成(“mybatis-config.xml”)。
以上是“Eclipse中如何使用Maven創(chuàng)建Java Web工程”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享標(biāo)題:Eclipse中如何使用Maven創(chuàng)建JavaWeb工程-創(chuàng)新互聯(lián)
文章起源:http://chinadenli.net/article24/dggice.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、企業(yè)網(wǎng)站制作、網(wǎng)站收錄、網(wǎng)站改版、服務(wù)器托管、商城網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)