maven使用第三方jar,適合新人

運行環境

  • JDK 1.8
  • eclipse Oxygen.3a Release
  • maven 4.00

使用本地jar包

1.打開cmd執行以下命令

mvn install:install-file -Dfile=jar-path -DgroupId=groupId -DartifactId=dartifactId -Dversion=version -Dpackaging=jar

需要配置命令 說明
-Dfile 將要引入jar包絕對路徑
-DgroupId 對應JAVA的包的結構
-DartifactId 對應項目的名稱
-Dversion jar版本號

2.配置pom.xml
根據以上表格中配置的命令,在pom.xml中添加相應配置

<project>
    ...
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
    ...
</project>

使用遠程倉庫

添加 central.maven 遠程倉庫的詳細信息在“pom.xml”文件。

<project>
    ...
    <repositories>
        <repository>
            <id>central maven</id>
            <url>http://central.maven.org/maven2/</url>
        </repository>
    </repositories>
    ...
</project>

如果識別不成功,在項目根目錄執行命令(僅供參考)

1. mvn eclipse:clean
2. mvn eclipse:eclipse
3. eclipse中刪除項目(不刪除本地)
4. eclipse => import -> Existing Projects
5. 完成
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章