Eclipse中的maven项目引入jar报错的解决方式
一、背景
最近在学习es的使用,先是在一个电脑上写的测试代码,然后代码复制另一台电脑上,没想到maven项目里的pom.xml居然报错了。所以在这里记录一下解决的方式。
(异常是复现的,非第一现场,仅作示例)
二、问题表现
1、从项目上看的表现
2、打开pom的表现
3、定位到×的地方
null (org.apache.maven.plugins:maven-jar-plugin:2.4:jar:default-jar:package) org.eclipse.core.runtime.operationcanceledexception at org.eclipse.core.runtime.submonitor.checkcanceled(submonitor.java:604) at org.eclipse.core.internal.resources.resource.setderived(resource.java:1611) at org.eclipse.m2e.core.internal.m2eutils.createfolder(m2eutils.java:73) at org.sonatype.m2e.mavenarchiver.internal.abstractmavenarchiverconfigurator.writepom(abstractmavenarchiverconfigurator.java:772) at org.sonatype.m2e.mavenarchiver.internal.abstractmavenarchiverconfigurator$1.build(abstractmavenarchiverconfigurator.java:161) at org.eclipse.m2e.core.internal.builder.mavenbuilderimpl.build(mavenbuilderimpl.java:137) at org.eclipse.m2e.core.internal.builder.mavenbuilder$1.method(mavenbuilder.java:172) at org.eclipse.m2e.core.internal.builder.mavenbuilder$1.method(mavenbuilder.java:1) at org.eclipse.m2e.core.internal.builder.mavenbuilder$buildmethod$1$1.call(mavenbuilder.java:115) at org.eclipse.m2e.core.internal.embedder.mavenexecutioncontext.executebare(mavenexecutioncontext.java:177) at org.eclipse.m2e.core.internal.embedder.mavenexecutioncontext.execute(mavenexecutioncontext.java:112) at org.eclipse.m2e.core.internal.builder.mavenbuilder$buildmethod$1.call(mavenbuilder.java:105) at org.eclipse.m2e.core.internal.embedder.mavenexecutioncontext.executebare(mavenexecutioncontext.java:177) at org.eclipse.m2e.core.internal.embedder.mavenexecutioncontext.execute(mavenexecutioncontext.java:151) at org.eclipse.m2e.core.internal.embedder.mavenexecutioncontext.execute(mavenexecutioncontext.java:99) at org.eclipse.m2e.core.internal.builder.mavenbuilder$buildmethod.execute(mavenbuilder.java:86) at org.eclipse.m2e.core.internal.builder.mavenbuilder.build(mavenbuilder.java:200) at org.eclipse.core.internal.events.buildmanager$2.run(buildmanager.java:735) at org.eclipse.core.runtime.saferunner.run(saferunner.java:42) at org.eclipse.core.internal.events.buildmanager.basicbuild(buildmanager.java:206) at org.eclipse.core.internal.events.buildmanager.basicbuild(buildmanager.java:246) at org.eclipse.core.internal.events.buildmanager$1.run(buildmanager.java:301) at org.eclipse.core.runtime.saferunner.run(saferunner.java:42) at org.eclipse.core.internal.events.buildmanager.basicbuild(buildmanager.java:304) at org.eclipse.core.internal.events.buildmanager.basicbuildloop(buildmanager.java:360) at org.eclipse.core.internal.events.buildmanager.build(buildmanager.java:383) at org.eclipse.core.internal.events.autobuildjob.dobuild(autobuildjob.java:142) at org.eclipse.core.internal.events.autobuildjob.run(autobuildjob.java:232) at org.eclipse.core.internal.jobs.worker.run(worker.java:56)
还有一个×(有时有的×能点,有的不能点)
multiple annotations found at this line:
- failure to transfer org.apache.httpcomponents:httpcore:jar:4.4.12 from http://maven.***.com:port/nexus/content/groups/public was cached in the local repository, resolution will not be
reattempted until the update interval of nexus-public-corp-releases has elapsed or updates are forced. original error: could not transfer artifact org.apache.httpcomponents:httpcore:jar:4.4.12 from/to
nexus-public-corp-releases (http://maven.***.com:port/nexus/content/groups/public): the operation was cancelled. org.eclipse.aether.transfer.artifacttransferexception: failure to transfer
org.apache.httpcomponents:httpcore:jar:4.4.12 from http://maven.***.com:port/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update
interval of nexus-public-corp-releases has elapsed or updates are forced. original error: could not transfer artifact org.apache.httpcomponents:httpcore:jar:4.4.12 from/to nexus-public-corp-releases
(http://maven.***.com:port/nexus/content/groups/public): the operation was cancelled. at
org.eclipse.aether.internal.impl.defaultupdatecheckmanager.newexception(defaultupdatecheckmanager.java:238) at
org.eclipse.aether.internal.impl.defaultupdatecheckmanager.checkartifact(defaultupdatecheckmanager.java:206) at
org.eclipse.aether.internal.impl.defaultartifactresolver.gatherdownloads(defaultartifactresolver.java:585) at
org.eclipse.aether.internal.impl.defaultartifactresolver.performdownloads(defaultartifactresolver.java:503) at org.eclipse.aether.internal.impl.defaultartifactresolver.resolve(defaultartifactresolver.java:421)
at org.eclipse.aether.internal.impl.defaultartifactresolver.resolveartifacts(defaultartifactresolver.java:246) at
org.eclipse.aether.internal.impl.defaultrepositorysystem.resolvedependencies(defaultrepositorysystem.java:367) at
org.apache.maven.project.defaultprojectdependenciesresolver.resolve(defaultprojectdependenciesresolver.java:205) at
org.apache.maven.project.defaultprojectbuilder.resolvedependencies(defaultprojectbuilder.java:215) at org.apache.maven.project.defaultprojectbuilder.build(defaultprojectbuilder.java:188) at
org.apache.maven.project.defaultprojectbuilder.build(defaultprojectbuilder.java:119) at org.eclipse.m2e.core.internal.embedder.mavenimpl.readmavenproject(mavenimpl.java:636) at
org.eclipse.m2e.core.internal.project.registry.defaultmavendependencyresolver.resolveprojectdependencies(defaultmavendependencyresolver.java:63) at
org.eclipse.m2e.core.internal.project.registry.projectregistrymanager.refreshphase2(projectregistrymanager.java:530) at
org.eclipse.m2e.core.internal.project.registry.projectregistrymanager$3.call(projectregistrymanager.java:492) at
org.eclipse.m2e.core.internal.project.registry.projectregistrymanager$3.call(projectregistrymanager.java:1) at
org.eclipse.m2e.core.internal.embedder.mavenexecutioncontext.executebare(mavenexecutioncontext.java:177) at
org.eclipse.m2e.core.internal.embedder.mavenexecutioncontext.execute(mavenexecutioncontext.java:151) at
三、定位、解决问题
1、定位问题
从上述的那个×的描述,可以看到原因。
org.eclipse.core.runtime.operationcanceledexception
操作被取消异常。
也就是在引入依赖的时候,maven还在下载jar包时被终止了。
我的项目出现上述异常,就是因为下的过程中网络卡了,然后我就手动结束了下载过程。
这种问题之前遇到过,当时总怀疑是项目结构有问题,或者jar有问题,没有想到是这个原因。
这次又遇到这个问题的时候,我回想,在自己电脑上都正常,在公司电脑就有问题?不应该。
问题定位了,接下来就是解决问题了。
2、解决问题
打开项目的build path,可以看到libraries中的maven依赖那块有×。
展开之后,就可以看到是哪个jar包异常。
根据路径找到本地的maven仓库对应的路径。可以点进去看一下,有几个文件,但是没有jar文件。
解决方法:删除4.4.12这个文件夹。然后随意改动一下pom.xml后保存,让eclipse重新下一下,问题就解决了。
上一篇: 刘邦的情商有多高?为什么有那么多人愿意死心塌地追随他?
下一篇: 回家叫家长
推荐阅读
-
Eclipse中引入com.sun.image.codec.jpeg包报错的完美解决办法
-
Eclipse中的maven项目引入jar报错的解决方式
-
解决eclipse中maven引用不到已经存在maven中jar包的问题
-
解决运行maven打的Avro项目jar包,报错第三方库的类找不到
-
springboot项目maven打包编译第三方jar包,报错:找不到符号,找不到jar中的类
-
Eclipse中引入com.sun.image.codec.jpeg包报错的完美解决办法
-
解决:打包SpringBoot项目成jar包后,其他的项目无法引入jar包中的对象
-
Eclipse中的maven项目引入jar报错的解决方式
-
解决使用maven将项目打包成jar包后运行在linux系统中无法读取jar包中文件的问题
-
解决eclipse中maven引用不到已经存在maven中jar包的问题