将外部JAR包添加到Maven本地仓库

4

我第一次使用maven。我试图将spring-core.jar添加到我的本地maven仓库中。我尝试的方法是:

C:\Users\user\.m2\repository>mvn install:install-file -Dfile=C:\spring-core-4.2.0.RELEASE.jar -DgroupId=org.springframework -DartifactId=spring-core -Dversion=4.2.0.RELEASE -Dpackaging=jar

但我最终遇到了以下错误。
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) @ standalone-pom ---
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/3.0.5/plexus-utils-3.0.5.pom
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://repo.maven.apache.org:443: Unrecognized Windows Sockets error: 10106: create
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://repo.maven.apache.org:443
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://repo.maven.apache.org:443: Unrecognized Windows Sockets error: 10106: create
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://repo.maven.apache.org:443
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://repo.maven.apache.org:443: Unrecognized Windows Sockets error: 10106: create
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://repo.maven.apache.org:443
Downloading: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-digest/1.0/plexus-digest-1.0.pom
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://repo.maven.apache.org:443: Unrecognized Windows Sockets error: 10106: create
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://repo.maven.apache.org:443
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://repo.maven.apache.org:443: Unrecognized Windows Sockets error: 10106: create
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://repo.maven.apache.org:443
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: I/O exception (java.net.SocketException) caught when processing request to {s}->https://repo.maven.apache.org:443: Unrecognized Windows Sockets error: 10106: create
Dec 12, 2015 11:56:38 AM org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute
INFO: Retrying request to {s}->https://repo.maven.apache.org:443
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.414 s
[INFO] Finished at: 2015-12-12T11:56:38+05:30
[INFO] Final Memory: 9M/108M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install-file (default-cli) on project standalone-pom: Execution default-cli of goal org.apache.maven
.plugins:maven-install-plugin:2.4:install-file failed: Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved: Failed to collect d
ependencies at org.apache.maven.plugins:maven-install-plugin:jar:2.4 -> org.codehaus.plexus:plexus-utils:jar:3.0.5: Failed to read artifact descriptor for org.codehaus.plexus:plexus
-utils:jar:3.0.5: Could not transfer artifact org.codehaus.plexus:plexus-utils:pom:3.0.5 from/to central (https://repo.maven.apache.org/maven2): Unrecognized Windows Sockets error:
10106: create -> [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/PluginResolutionException

请有人帮我解决这个错误,同时告诉我如何将外部JAR文件添加到我的Maven仓库。谢谢。

2个回答

3

这个消息:

java.net.SocketException: Unrecognized Windows Sockets error: 10106: create

意味着Maven无法打开端口10106。可能是该端口被阻止或者已经被占用。

扫描端口,例如在Windows下:

Windows+R ---> cmd ---> enter
netstat -b


2

@letmedoit : 你能解释一下为什么需要手动将构件添加到本地的maven仓库吗?

依我之见,最好创建一个pom.xml文件并直接运行它。

在你的电脑上的某个位置添加这个文件(pom.xml):

<?xml version="1.0" encoding="UTF-8"?> <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/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>你的GroupId</groupId> <artifactId>你的ArtifactId</artifactId> <version>0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.2.0.RELEASE</version> </dependency> </dependencies> </project>

然后只需在放置前述文件的目录中运行maven命令:mvn compile

它应该执行构件的下载,如下所示: [INFO] 搜索项目... [INFO]
[INFO] ------------------------------------------------------------------------ [INFO] 正在构建 yourArtifactId 0-SNAPSHOT [INFO] ------------------------------------------------------------------------ 正在下载:https://repo.maven.apache.org/maven2/org/springframework/spring-core/4.2.0.RELEASE/spring-core-4.2.0.RELEASE.pom 已下载:https://repo.maven.apache.org/maven2/org/springframework/spring-core/4.2.0.RELEASE/spring-core-4.2.0.RELEASE.pom (3 KB,速度为5.4 KB / 秒) 正在下载:https://repo.maven.apache.org/maven2/org/springframework/spring-core/4.2.0.RELEASE/spring-core-4.2.0.RELEASE.jar 已下载:https://repo.maven.apache.org/maven2/org/springframework/spring-core/4.2.0.RELEASE/spring-core-4.2.0.RELEASE.jar(1028 KB,速度为78.9 KB / 秒) [INFO] [INFO] --- maven-resources-plugin:2.6:resources(default-resources)@ yourArtifactId --- [WARNING] 使用平台编码(实际上为UTF-8)来复制过滤后的资源,即构建依赖于平台! [INFO] 跳过不存在的资源目录 /tmp/src/main/resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile(default-compile)@ yourArtifactId --- [INFO] 没有源代码需要编译 [INFO] ------------------------------------------------------------------------ [INFO] 构建成功 [INFO] ------------------------------------------------------------------------ [INFO] 总时间:15.455秒 [INFO] 完成于:2015-12-12T11:02:37+01:00 [INFO] 最终内存:10M / 147M [INFO] ------------------------------------------------------------------------

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接