[英]How to add a new jar file as a dependency to POM.xml of Java Maven web project?
我想從我的Java Web(Maven)項目連接到Lotus Notes(8.5.3)數據庫。 經過一些搜索之后,為了從Java Web項目通過CORBA DIIOP連接到Lotus Notes數據庫,我需要將NCSO.jar作為新的依賴項添加到我的Maven Java Web項目中。 我找到了此鏈接: 如何在pom.xml中添加\\ install到新創建的\\第三方jar的maven依賴項 ,但是我仍然不知道如何使其工作。 我可以從本地計算機上找到NCSO.jar,但是基於該鏈接,我需要為此文件創建自己的存儲庫,然后將其添加到pom.xml文件中。 這是我第一次向Java Web項目(pom.xml)添加.jar依賴項。 在我的Java Web項目中,我有EJB部分和Web部分,每個都有pom.xml。 不確定如何將此.jar添加到pom.xml。
my java IDE is built on eclipse, the current workspace structure is like this: The current workspace called: developer, it contains followings:
developer
workspaces (folder)
Java-2014prj (folder)
.settings (folder)
projEAR (folder)
projEJB (folder)
projWeb (folder)
src (folder)
.project
pom.xml
is this the correct commands? and if this is correct and no errors, what should I do after the command executed? are all POM.xml added the NCSO.jar?
c:\developer>mvn install:install-file
Dfile=c:\NCSO.jar
DgroupId=lotus
DartifactId=domino
Dversion=1.0.0
Dpackaging=.jar
DgeneratePom=true
projEAR,projEJB和projWeb也都包含pom.xml。 NCSO.jar位於我的本地c:/NCSO.jar中。 所以我想我應該在我的窗口命令(黑色)屏幕上運行代碼。 我應該在項目頂部文件夾c:\\ developer上運行它嗎? 或一些子文件夾? 我不知道如何創建本地存儲庫? 有人可以向我提供更多詳細信息嗎? 謝謝。
編輯-根據下面的公理說明我的結果
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] PARENT project of MARKETPROJ
[INFO] EJB project of MARKETPROJ
[INFO] WAR project of MARKETPROJ
[INFO] EAR project of MARKETPROJ
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-install-plugin/2.4/maven-install-plugin-2.4.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-install-plugin:2.4: Plugin org.apache.maven.plugins:maven-install-plugin:2.4 o
r one of its dependencies could not be resolved: Failed to read artifact descrip
tor for org.apache.maven.plugins:maven-install-plugin:jar:2.4
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-deploy-plugin:2.7: Plugin org.apache.maven.plugins:maven-deploy-plugin:2.7 or
one of its dependencies could not be resolved: Failed to read artifact descripto
r for org.apache.maven.plugins:maven-deploy-plugin:jar:2.7
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-site-plugin/3.3/maven-site-plugin-3.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-site-plugin:3.3: Plugin org.apache.maven.plugins:maven-site-plugin:3.3 or one
of its dependencies could not be resolved: Failed to read artifact descriptor fo
r org.apache.maven.plugins:maven-site-plugin:jar:3.3
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-antrun-plugin/1.3/maven-antrun-plugin-1.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-antrun-plugin:1.3: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.3 or
one of its dependencies could not be resolved: Failed to read artifact descripto
r for org.apache.maven.plugins:maven-antrun-plugin:jar:1.3
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-assembly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-assembly-plugin:2.2-beta-5: Plugin org.apache.maven.plugins:maven-assembly-plu
gin:2.2-beta-5 or one of its dependencies could not be resolved: Failed to read
artifact descriptor for org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-b
eta-5
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-dependency-plugin/2.8/maven-dependency-plugin-2.8.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-dependency-plugin:2.8: Plugin org.apache.maven.plugins:maven-dependency-plugin
:2.8 or one of its dependencies could not be resolved: Failed to read artifact d
escriptor for org.apache.maven.plugins:maven-dependency-plugin:jar:2.8
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-release-plugin/2.3.2/maven-release-plugin-2.3.2.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:mave
n-release-plugin:2.3.2: Plugin org.apache.maven.plugins:maven-release-plugin:2.3
.2 or one of its dependencies could not be resolved: Failed to read artifact des
criptor for org.apache.maven.plugins:maven-release-plugin:jar:2.3.2
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metada
ta.xml
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-metadata.xml
[WARNING] Could not transfer metadata org.apache.maven.plugins/maven-metadata.xm
l from/to central (https://repo.maven.apache.org/maven2): Failed to transfer fil
e: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.
xml. Return code is: 501 , ReasonPhrase:Not Implemented.
[WARNING] Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/
to central (https://repo.maven.apache.org/maven2): Failed to transfer file: http
s://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml. Return co
de is: 501 , ReasonPhrase:Not Implemented.
[WARNING] Failure to transfer org.apache.maven.plugins/maven-metadata.xml from h
ttps://repo.maven.apache.org/maven2 was cached in the local repository, resoluti
on will not be reattempted until the update interval of central has elapsed or u
pdates are forced. Original error: Could not transfer metadata org.apache.maven.
plugins/maven-metadata.xml from/to central (https://repo.maven.apache.org/maven2
): Failed to transfer file: https://repo.maven.apache.org/maven2/org/apache/mave
n/plugins/maven-metadata.xml. Return code is: 501 , ReasonPhrase:Not Implemented
.
[WARNING] Failure to transfer org.codehaus.mojo/maven-metadata.xml from https://
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. Original error: Could not transfer metadata org.codehaus.mojo/maven-
metadata.xml from/to central (https://repo.maven.apache.org/maven2): Failed to t
ransfer file: https://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metad
ata.xml. Return code is: 501 , ReasonPhrase:Not Implemented.
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] PARENT project of MARKETPROJ ............................. SKIPPED
[INFO] EJB project of MARKETPROJ ................................ SKIPPED
[INFO] WAR project of MARKETPROJ ................................ SKIPPED
[INFO] EAR project of MARKETPROJ ................................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.624 s
[INFO] Finished at: 2015-01-18T13:30:32-05:00
[INFO] Final Memory: 9M/244M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix 'deploy' in the current project and in the pl
ugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the rep
ositories [local (C:\Users\jsmith\.m2\repository), central (https://repo.maven.apa
che.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e swit
ch.
[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 rea
d the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundF
orPrefixException
********************************
**EDIT again:**
I just checked my pom.xml again, and found we have these codes
<!-- local file-based repository on the team's shared drive -->
<repository>
<id>MARKETPROJ-repo-local</id>
<name>MARKETPROJ File Based Internal Repository</name>
<url>file://\\mark\mark_shrdata\MARKETPROJ\maven2\repo</url>
</repository>
如果您的依賴項在公共存儲庫中不可用,則需要將依賴項安裝到本地Maven存儲庫中。 您可能會想將其安裝到~/.m2/repository
,這是該問題的其他答案所提出的方法。 如果您這樣做,則該構建將在該計算機上正常運行。 但這不是最佳解決方案。 實際上,這是一個糟糕的解決方案,因為項目構建依賴於此手動安裝的工件。 如果刪除~/.m2/repository
目錄,則構建將失敗,因為工件不再位於存儲庫中。
如果必須在本地安裝依賴項,則最好將其安裝到項目本地存儲庫中,然后將整個存儲庫提交到版本控制系統中。 這樣,如果您與其他人(包括您在另一台計算機上)共享項目,則該構建對於其他人仍然有效,他們也不必在本地安裝依賴項。
有關詳細說明,請參見此處: https : //devcenter.heroku.com/articles/local-maven-dependencies
例如,如果您的項目如下所示:
yourproject
+- pom.xml
+- src
然后,您可以創建一個項目本地存儲庫,如下所示:
yourproject
+- pom.xml
+- src
+- repo
然后使用以下命令將依賴項安裝到項目本地存儲庫中:
mvn deploy:deploy-file -Durl=file:///path/to/yourproject/repo/ -Dfile=NCSO.jar -DgroupId=ncso -DartifactId=ncso -Dpackaging=jar -Dversion=1.0
因此,您的項目現在將如下所示:
yourproject
+- pom.xml
+- src
+- repo
+- nsco
+- ncso
+- maven-metadata.xml
+- ...
+- 1.0
+- ncso-1.0.jar
+- ncso-1.0.pom
+- ...
然后將您的項目本地存儲庫告訴您的項目pom.xml文件:
<repositories>
<!--other repositories if any-->
<repository>
<id>project.local</id>
<name>project</name>
<url>file:${project.basedir}/repo</url>
</repository>
</repositories>
並將您的項目本地依賴項也添加到pom.xml中:
<dependency>
<groupId>ncso</groupId>
<artifactId>ncso</artifactId>
<version>1.0</version>
</dependency>
編輯-根據評論中的問題。
假設您已將需要部署的依賴項臨時存儲在C:驅動器的根目錄下的項目本地Maven存儲庫中,並且您的項目也存儲在C:驅動器的根目錄下,那么C:驅動器看起來像這個:
C:/NCSO.JAR
C:/yourproject
C:/yourproject/pom.xml
C:/yourproject/src
C:/yourproject/repo
同樣假設您在C:驅動器根目錄下的命令提示符中運行以下命令,那么這將是您用來將依賴項安裝到項目本地存儲庫中的命令:
C:\> mvn deploy:deploy-file -Durl=file:///C:/yourproject/repo/ -Dfile=NCSO.jar -DgroupId=ncso -DartifactId=ncso -Dpackaging=jar -Dversion=1.0
成功運行此命令后,可以刪除文件C:/NCSO.jar
。 不再需要它,因為它已安裝(復制)到您的項目本地存儲庫中。 此時,您還需要將C:/yourproject/repo
及其所有數據添加到版本控制系統中,以便repo文件夾及其內部的所有數據成為項目的永久部分。
使用cmd提示符或終端,按照鏈接的建議mvn安裝jar,以便將其創建在.m2存儲庫中,然后將以下內容添加到pom.xml中
以cmd提示或三進制:
mvn install:install-file -Dfile="path-to-jar-file" -DgroupId=com.project.ncso -DartifactId=ncso -Dversion=1.0.0 -Dpackaging=jar
在項目目錄內的pom.xml中,添加以下內容:
<dependency>
<groupId>com.project.ncso</groupId>
<artifactId>ncso</artifactId>
<version>1.0.0</version>
</dependency>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.