日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Maven 手动安装Jar包的例子

發布時間:2025/3/16 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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.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

總結

以上是生活随笔為你收集整理的Maven 手动安装Jar包的例子的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。