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 參數(shù)。 在命令行,只要簡單的給任何目標(biāo)添加 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.忽略測試失敗
????? 當(dāng) Maven 遇到一個(gè)測試失敗,它默認(rèn)的行為是停止當(dāng)前的構(gòu)建。 如果你希望繼續(xù)構(gòu)建項(xiàng)目,即使 Surefire 插件遇到了失敗的單元測試,你就需要設(shè)置 Surefire 的 testFailureIgnore 這個(gè)配置屬性為 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.打包應(yīng)用程序
???? Maven Assembly 插件是一個(gè)用來創(chuàng)建你應(yīng)用程序特有分發(fā)包的插件。要配置 Maven Assembly 插件, 我們需要在 pom.xml 中的 build 配置中添加如下的 plugin 配置。
??? <plugin>
??????? <artifactId>maven-assembly-plugin</artifactId>
??????? <configuration>
????????? <descriptorRefs>
??????????? <descriptorRef>jar-with-dependencies</descriptorRef>
????????? </descriptorRefs>
??????? </configuration>
???? </plugin>
5.創(chuàng)建Web項(xiàng)目
?????? mvn archetype:create -DgroupId=org.company.lms?? -DartifactId=lms?? -DpackageName=org.company.lms?? -DarchetypeArtifactId=maven-archetype-webapp
6.配置Jetty服務(wù)器
??? <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.創(chuàng)建多模塊項(xiàng)目:
? 若項(xiàng)目的根目錄為lms,在此目錄內(nèi)依次創(chuàng)建各個(gè)要劃分的模塊,如系統(tǒng)分四層(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
? 生成完各個(gè)模塊后,在lms目錄下,放入一個(gè)pom.xml文件,其內(nèi)容如下:
<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.0 http://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
總結(jié)
以上是生活随笔為你收集整理的Maven 手动安装Jar包的例子的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 在web项目中的类库中引用webserv
- 下一篇: 17个之多!Windows Vista各