1.配置项目远程仓库:
1.配置项目远程仓库:
setting.xml文件很重要,
clean
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
MAVEN常用命令:
用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 主要用到的配置文件
1,chang
部署:
右键项目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插件中可以设置路径,端口号