2012-09-25

在 Maven Repository 找不到的 jar 檔?

太新的 jar 檔?太少見的 jar 檔?有版權的 jar 檔?自家的 jar 檔?就是有些 jar 檔不會出現在 Maven 的 The Central Repository 裡。

怎辦?如果手邊有這個 jar 檔,那就安裝在自己的 Local Repository 裡。

以前的 Maven 2 遇到找不到的 jar 檔時,都會很好心的直接吐出安裝的語法供使用,升級到 Maven 3 之後,這個好心的建議不見了。

Maven 2 的執行訊息。
D:\_Work\Aproject>mvn package
[INFO] Scanning for projects...
...
Downloading: http://repo1.maven.org/maven2/foo/boo/1/boo-1.pom
[INFO] Unable to find resource 'foo:boo:pom:1' in repository central (http://repo1.maven.org/maven2)
Downloading: http://repo1.maven.org/maven2/foo/boo/1/boo-1.jar
[INFO] Unable to find resource 'foo:boo:jar:1' in repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.

Missing:
----------
1) foo:boo:jar:1

  Try downloading the file manually from the project website.

  Then, install it using the command:
      mvn install:install-file -DgroupId=foo -DartifactId=boo -Dversion=1 -Dpackaging=jar -Dfile=/path/to/file

  Alternatively, if you host your own repository you can deploy the file there:

      mvn deploy:deploy-file -DgroupId=foo -DartifactId=boo -Dversion=1 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
...
Maven 3 的執行訊息。
D:\_Work\Aproject>mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Aproject 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.391s
[INFO] Finished at: Tue Sep 25 10:10:32 CST 2012
[INFO] Final Memory: 5M/15M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project Aproject: Could not resolve dependencies for project idv.neil:Aproject:jar:1.0-SNAPSHOT: Failure to find foo:boo:jar:1 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
所以做個筆記供以後參考使用。
mvn install:install-file -DgroupId=foo -DartifactId=boo -Dversion=1 -Dpackaging=jar -Dfile=/path/to/file
可以再加上 -Dsources=src.jar 來補上 Source code,全部參數在官網
---

沒有留言:

張貼留言