eclipse如何创建maven项目并打包項目到本地庫中

创建maven项目:

1.下载maven插件

2.打开preference->maven->installations->add(添加maven插件的路径)

3.new->maven project->全部勾选->next->package选择war->finish

4.在src/main/webapp里创建web.xml

5.打开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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>cn.wu.test</groupId>
  <artifactId>demo</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  
  <dependencies>
      <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>servlet-api</artifactId>
           <version>2.5</version>
      </dependency>
      <dependency>
           <groupId>javax.servlet.jsp</groupId>
           <artifactId>jsp-api</artifactId>
           <version>2.1</version>
      </dependency>
      <dependency>
           <groupId>javax.servlet</groupId>
           <artifactId>jstl</artifactId>
           <version>1.2</version>
      </dependency>
  </dependencies>
  
  
</project>

记得web.xml中的版本声明,要和pom.xml中的javax.servet.servlet.api的版本一致。

<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_2_5.xsd" id="WebApp_ID" version="2.5">

点击保存时maven插件就会自动下载对应的包。

打包到本地库:

右键点击项目,选择 run as ->maven install

如果执行Maven Install打包的时候,提示以下警告信息: 
[WARNING] Using platform encoding (GBK actually) to copy filtered resources, i.e. build is platform dependent!

解决方法: 

右键打开项目属性properties->Resources->Other->utf-8

posted @ 2018-07-10 16:07  吴桂鑫  阅读(916)  评论(0)    收藏  举报