Maven 手动安装Jar包的例子

                 

1.若POM.XML中有如下JAR包不能自动下载:
<dependency>
            <groupId>castor</groupId>
            <artifactId>castor</artifactId>
            <version>1.0</version>
            <scope>compile</scope>
 </dependency>
 

手动安装命令如下:

 mvn install:install-file -DgroupId=castor -DartifactId=castor
 -Dversion=1.0 -Dpackaging=jar -Dfile=c:\castor-1.0.jar
 

2.跳过单元测试
     Maven 提供了跳过单元测试的能力,只需要使用 Surefire 插件的 skip 参数。 在命令行,只要简单的给任何目标添加 maven.test.skip 属性就能跳过测试:
mvn install -Dmaven.test.skip=true
<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <skip>true</skip>
        </configuration>
</plugin>

3.忽略测试失败
      当 Maven 遇到一个测试失败,它默认的行为是停止当前的构建。 如果你希望继续构建项目,即使 Surefire 插件遇到了失败的单元测试,你就需要设置 Surefire 的 testFailureIgnore 这个配置属性为 true。
mvn test -Dmaven.test.failure.ignore=true
   <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <testFailureIgnore>true</testFailureIgnore>
        </configuration>
   </plugin>

4.打包应用程序
     Maven Assembly 插件是一个用来创建你应用程序特有分发包的插件。要配置 Maven Assembly 插件, 我们需要在 pom.xml 中的 build 配置中添加如下的 plugin 配置。
    <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
     </plugin>

5.创建Web项目
       mvn archetype:create -DgroupId=org.company.lms   -DartifactId=lms   -DpackageName=org.company.lms   -DarchetypeArtifactId=maven-archetype-webapp

6.配置Jetty服务器
    <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
    </plugin>
7.添加servle依赖的包
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-servlet_2.4_spec</artifactId>
      <version>1.1.1</version>
      <scope>provided</scope>
    </dependency>

8.创建多模块项目:
  若项目的根目录为lms,在此目录内依次创建各个要划分的模块,如系统分四层(model,dao,service,web),每层都可有自己的模块.
  mvn archetype:create -DgroupId=com.company.lms.model  -DartifactId=lms-model
  mvn archetype:create -DgroupId=com.company.lms.dao     -DartifactId=lms-dao
  mvn archetype:create -DgroupId=com.company.lms.service -DartifactId=lms-service
  mvn archetype:create -DgroupId=com.company.lms.web     -DartifactId=lms-web
  生成完各个模块后,在lms目录下,放入一个pom.xml文件,其内容如下:
<project xmlns="
http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
http://maven.apache.org/POM/4.0.0http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
          <groupId>lms</groupId>
          <artifactId>lms</artifactId>
          <packaging>pom</packaging>   <!--注意,这里的打包类型不再是jar或war-->
          <version>1.0-SNAPSHOT</version>
          <name>parent</name>
          <url>http://maven.apache.org</url>
          <modules>
             <module>lms-model</module>
             <module>lms-dao</module> 
             <module>lms-service</module>
             <module>lms-web</module>     
  </modules> 
  <!--其它省略-->
</project>

 

 

参考资料:http://www.sonatype.com

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

猜你喜欢

转载自blog.csdn.net/fswhwd/article/details/87261218