Maven使用

如何下载安装

从maven官网下载一个压缩包,解压。
设置环境变量 M2_HOME 为 maven的根目录。
添加maven的bin目录到path中。

如何配置国内源

在maven 的conf目录下,修改setting.xml文件。找到mirrors 标签,替换为下面的内容

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

如何命令行创建工程

直接创建maven web项目:
mvn archetype:generate -DarchetypeCatalog=internal -DgroupId=your.com -DartifactId=myweb -DarchetypeArtifactId=maven-archetype-webapp

Maven的目录结构

src/main/java 源代码
src/main/resources 资源,会被编译到classes目录下
src/main/webapp web项目的网站根目录
src/main/bin 脚本库
src/test 测试文件目录,其子目录与main相同。

pom.xml 最核心的配置文件
target/ 生成的文件

常用命令

mvn compile 变异
mvn package 打包
mvn install 安装到本地库

如何使用jetty 运行web工程

在pom.xml 的build标签下添加以下内容

    <plugins>
      <plugin>
                      <groupId>org.mortbay.jetty</groupId>
                      <artifactId>jetty-maven-plugin</artifactId>
                      <!--jdk1.7-->
                      <!--version>7.1.0.RC1</version-->
                      <!--jdk1.8-->
                      <version>8.1.16.v20140903</version>
                      <configuration>
                          <webAppConfig>
                              <contextPath>/</contextPath>
                          </webAppConfig>
                      </configuration>
        </plugin>
    </plugins>

如何运行
mvn jetty:run

猜你喜欢

转载自blog.csdn.net/taiji1985/article/details/79956903
今日推荐