2840人加入学习
(4人评价)
3小时学会使用Maven构建项目

制作完成于2018-10-30 使用Maven3.5.4 JDK1.8

价格 免费

1.配置项目远程仓库:

 

[展开全文]

<mirror>
        <id>alimaven</id>
      <mirrorOf>central</mirrorOf>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
 </mirror>

[展开全文]

用maven命令行构建项目:

1.先CD到项目根目录,比如HelloMaven

2.执行:mvn tomcat:run\

3.浏览器访问:http://localhost:8080/HelloMaven/test

4.总结:操作系统无需安装IDE和tomcat

[展开全文]

Maven常用命令:

1.clean: 清理,编译后的target目录;

2.compile: 编译,只编译main目录,不编译test中的代码。编译后生成target目录。

3.test-compile:编译test目录中的代码

4.test 运行test里边的代码

5.package 打包①java项目->打成jar包②web项目->打成war包

6.install:发布项目到本地仓库,用在打jar包上,打成jar包可以被其他项目使用。(发布war包mei'y'y)

7.tomcat:run:一键构建项目。

 

 

[展开全文]

Scope依赖作用域也可称作依赖范围:maven中的依赖,会根据程序所处的阶段和场景发生变化,所以maven用scope属性来做限制;
a)compile(默认值):在编译、运行、测试、打包都有效;
b)provided:编译、测试时有效,运行、打包无效;
c)test:仅在测试时有效;
d)runtime:测试、运行、打包时有效;
e)system:不推荐使用,使用system作用域不会去本地仓库寻找依赖,要指定本地路径;

 

一般tomcat和servlet用provided,junit用test,jdbcdriver用runtime

[展开全文]

conf配置文件

settings.xml 主要用到的配置文件

[展开全文]

部署:

右键项目Run AS->Maven build->Goals:tomcat:run

 

测试:

locahost:8080/HelloMaven/test ,网页内容Hello Maven

 

tomcat 6.0.29 默认版本

[展开全文]

Tomcat7,可以省略web.xml中的《servlet》部分

 

运行: mvn tomcat7:run

 

作用域:servlet和tomcat作用域都是provided

<dependency>
   <groupId>org.apache.tomcat</groupId>
   <artifactId>tomcat-servlet-api</artifactId>
   <version>8.5.32</version>
   <scope>provided</scope>
</dependency>
<dependency>
   <groupId>org.apache.tomcat</groupId>
   <artifactId>tomcat-jsp-api</artifactId>
   <version>8.5.32</version>
   <scope>provided</scope>
</dependency>

 

在tomcat7插件中可以设置路径,端口号

[展开全文]