一、背景
最近在学习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重新下一下,问题就解决了。