Maven基础学习总结

Maven学习总结

1. Maven基本命令

          mvn test-compile      编译测试代码

          mvn test                    运行应用程序中的单元测试

          mvn site                    生成项目相关信息的网站

          mvn clean                 清楚项目中的生成结果

          mvn package            根据项目生成jar

          mvn install                 在本地repo中安装jar

          mvn deploy                发布项目

          mvn compile              编译源码

          mvn archetype           创建源码项目

2. Maven的聚合集成

聚合:

  1. create a simple project (skip archetype selection)
  2. artifactId:项目名-aggregator
  3. packaging:pom
  4. 在pom.xml中写

          <modules>

                    <module>../子项目名1</module>

                    <module>../子项目名2</module>

          </modules>

集成:

          1. 同上1,2,在pom.xml中,在每个子项目的pom.xml中

          <parent>

                    <groupId>项目整体的名称 </groupId>

                    <artifactId>父项目名</artifactId>

                    <version>父项目名版本</version>

                     <relativePath>../父项目名/pom.xml</relativePath>

          </parent>

          2. 在parent的pom.xml中

          <properties>

                     <spring.version>4.3.5.RELEASE</ spring.version>

                     …管理版本…

          </properties>

          <dependencyManagement>

          <dependencies>

                    <dependency>

                              <groupId>jar包相关的项目整体的名称</groupId>

                              <artifactId>jar包名</artifactId>

                              <version>${project.version}</version>

                    </dependency>

                    …

           </dependencies>

          </ dependencyManagement>

3. 注意的是,每当更换工作空间时,在preference中要设置好settings,同时在settings.xml中加入mirror,指定使用国内的阿里云镜像包,建议使用阿里云的镜像库文件:

           <mirror>

                       <id>nexus</id>

                       <mirrorOf>*</mirrorOf>

                       <url>http://maven.aliyun.com/nexus/content/groups/public/</url>

            </mirror>

            <mirror>

                    <id>nexus-public-snapshots</id>

                    <mirrorOf>public-snapshots</mirrorOf>

                       <url>http://maven.aliyun.com/nexus/content/repositories/snapshots/</url>

            </mirror>

4. Maven的依赖特性:最短路径原则、最先申明原则

5. Maven的常见问题总结:

           1》 maven -- 问题解决(二)解决“Could not calculate build plan”问题

           https://www.cnblogs.com/lmei/p/4780453.html

           2》 SSH框架整合出现“LifecycleProcessor not initialized - call 'refresh' before invoking”问题

           https://blog.csdn.net/alan_liuyue/article/details/53302216 缺少jar包

           3》 当mvn中央仓库中没有想要的jar包时,需要手动添加jar

           https://blog.csdn.net/qq_30698633/article/details/78328842

           示例:

           mvn install:install-file -Dfile=lucene-queryparser-4.6.1.jar -DgroupId=org.apache.lucene -DartifactId=lucene-queryparser -           Dversion=4.6.1 -Dpackaging=jar

           4》Description Resource Path Location Type Archive for required library: 'D:/repository/ued

           https://blog.csdn.net/tengdazhang770960436/article/details/53105509

           5》maven编译时出现读取XXX时出错invalid LOC header (bad signature)

           https://blog.csdn.net/woshixuye/article/details/14669929

猜你喜欢

转载自blog.csdn.net/Juwenzhe_HEBUT/article/details/82024050