Maven入门
Maven入门1.为什么需要Maven当一些依赖在项目中重复导入引发问题时,当一个项目多个模块同时开发缺乏管理时,当配置、测试、部署频繁发生时,这时候Maven所提供的功能就能解决这些问题,当然,Maven远远不止这些功能。2.Maven是什么Maven, aYiddish word meaning accumulator of knowledge
Maven入门
1.为什么需要Maven
2.Maven是什么
Maven, a Yiddish word meaning accumulator of knowledge, was originally started as an attempt to simplify the build processes in the Jakarta Turbine project. There were several projects each with their own Ant build files that were all slightly different and JARs were checked into CVS. We wanted a standard way to build the projects, a clear definition of what the project consisted of, an easy way to publish project information and a way to share JARs across several projects.
The result is a tool that can now be used for building and managing any Java-based project. We hope that we have created something that will make the day-to-day work of Java developers easier and generally help with the comprehension of any Java-based project.
参考: What is Maven
3.Maven安装及配置
3.1 配置阿里云的云仓库
1.在<mirrors>元素中加入:
<mirror>
<id>aliyun</id>
<mirrorOf>centeral</mirrorOf>
<name>aliyun mirror</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</mirror>
2.在<profiles>元素中加入:
<profile>
<id>aliyun</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>aliyun</id>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
</pluginRepository>
</pluginRepositories>
</profile>
4.pom.xml文件的基本介绍
5.基本命令
- mvn archetype:generate 使用模板生成项目
- mvn compile 编译
- mvn test 单元测试
- mvn package 打成war包
- mvn deploy 部署项目
- mvn site 生成项目相关站点,在线文档
- mvn clean 清理操作
- mvn install 将包安装到本地仓库,让其他项目进行依赖
- mvn help:effective-pom 查看继承了父POM之后的POM文件的内容
6.Tomcat插件
- mvn help:describe -Dplugin=tomcat7 详细帮助
- mvn tomcat7:run 启动一个嵌入的Tomcat实例
- mvn tomcat:deploy 部署项目
- mvn tomcat:undeplay 取消部署项目
执行tomcat7插件相关的操作时,提示找不到tomcat7插件?
<pluginGroups>
<pluginGroup>org.apache.tomcat.maven</pluginGroup>
</pluginGroups>
Tomcat Maven插件配置
软件要求
具体配置
配置 tomcat 用户
打开 tomcat 安装目录,进入 conf 文件夹下,找到对应的 tomcat-users.xml 文件; 将文件中所有内容删除,加入以下内容并保存;<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<user username="admin" password="123456" roles="manager-gui,manager-script"/>
</tomcat-users>
Maven 中配置 Tomcat 服务器
<server>
<id>tomcat</id>
<username>admin</username>
<password>123456</password>
</server>
Tomcat Maven 插件配置
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<path>/web_project_template</path>
<uriEncoding>UTF-8</uriEncoding>
<finalName>web_project_template</finalName>
<server>tomcat</server>
</configuration>
</plugin>
运行
-------------参考《网易云课堂.Java Web开发入门》
更多推荐
所有评论(0)