Java Eclipse 在 Maven 更新期间抛出 NullPointerException

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19779141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 20:08:44  来源:igfitidea点击:

Eclipse throws NullPointerException during Maven update

javaeclipsemavenspring-tool-suite

提问by Robert J. Walker

I've been fighting an internal Eclipse error for two days. I'm running the latest Spring Tool Suite edition of Eclipse, and I've attempting to import a collection of existing Maven projects. Whenever I do so, Eclipse throws a NullPointerException, but no stack trace is available from the Error Log view. If I instruct Eclipse to update the Maven project (Maven > Update Project), I get a NullPointerException again. This time, the Error Log view reports the following stack trace:

两天来,我一直在与内部 Eclipse 错误作斗争。我正在运行最新的 Spring Tool Suite 版本的 Eclipse,并且我试图导入现有 Maven 项目的集合。每当我这样做时,Eclipse 都会抛出 NullPointerException,但错误日志视图中没有可用的堆栈跟踪。如果我指示 Eclipse 更新 Maven 项目(Maven > 更新项目),我将再次收到 NullPointerException。这一次,错误日志视图报告了以下堆栈跟踪:

java.lang.NullPointerException
    at org.eclipse.wst.common.componentcore.internal.resources.VirtualResource.getProjectRelativePaths(VirtualResource.java:119)
    at org.eclipse.wst.common.componentcore.internal.resources.VirtualFile.getUnderlyingFiles(VirtualFile.java:104)
    at org.eclipse.wst.common.componentcore.internal.resources.VirtualFile.getUnderlyingResources(VirtualFile.java:93)
    at org.eclipse.wst.common.componentcore.internal.resources.VirtualResource.exists(VirtualResource.java:88)
    at org.eclipse.jst.common.internal.modulecore.util.ManifestUtilities.getNonBinaryComponentManifest(ManifestUtilities.java:124)
    at org.eclipse.jst.common.internal.modulecore.util.ManifestUtilities.getManifest(ManifestUtilities.java:81)
    at org.eclipse.jst.common.internal.modulecore.util.ManifestUtilities.getManifestClasspath(ManifestUtilities.java:147)
    at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getManifestClasspath(J2EEModuleVirtualComponent.java:248)
    at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.calculateManifestReferences(J2EEModuleVirtualComponent.java:368)
    at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.cacheManifestReferences(J2EEModuleVirtualComponent.java:360)
    at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModuleVirtualComponent.java:176)
    at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModuleVirtualComponent.java:214)
    at org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModuleVirtualComponent.java:207)
    at org.eclipse.m2e.wtp.WebProjectConfiguratorDelegate.configureClasspath(WebProjectConfiguratorDelegate.java:386)
    at org.eclipse.m2e.wtp.WTPProjectConfigurator.configureClasspath(WTPProjectConfigurator.java:107)
    at org.eclipse.m2e.jdt.internal.DefaultClasspathManagerDelegate.populateClasspath(DefaultClasspathManagerDelegate.java:61)
    at org.eclipse.m2e.jdt.internal.BuildPathManager.getClasspath(BuildPathManager.java:253)
    at org.eclipse.m2e.jdt.internal.BuildPathManager.getClasspath(BuildPathManager.java:363)
    at org.eclipse.m2e.jdt.internal.BuildPathManager.getClasspath(BuildPathManager.java:343)
    at org.eclipse.m2e.jdt.internal.BuildPathManager.getClasspath(BuildPathManager.java:371)
    at org.eclipse.m2e.jdt.internal.BuildPathManager.updateClasspath(BuildPathManager.java:191)
    at org.eclipse.m2e.jdt.internal.BuildPathManager.mavenProjectChanged(BuildPathManager.java:180)
    at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.notifyProjectChangeListeners(ProjectRegistryManager.java:746)
    at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.applyMutableProjectRegistry(ProjectRegistryManager.java:865)
    at org.eclipse.m2e.core.internal.project.registry.ProjectRegistryManager.refresh(ProjectRegistryManager.java:289)
    at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.updateProjectConfiguration0(ProjectConfigurationManager.java:369)
    at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.call(ProjectConfigurationManager.java:316)
    at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.call(ProjectConfigurationManager.java:1)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:161)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:137)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:89)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1301)
    at org.eclipse.m2e.core.internal.project.ProjectConfigurationManager.updateProjectConfiguration(ProjectConfigurationManager.java:313)
    at org.eclipse.m2e.core.ui.internal.UpdateMavenProjectJob.runInWorkspace(UpdateMavenProjectJob.java:77)
    at org.eclipse.core.internal.resources.InternalWorkspaceJob.run(InternalWorkspaceJob.java:38)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)

Here's what I've tried:

这是我尝试过的:

  • I've blown away my workspace and created a new one. Multiple times.
  • I've blown away my Maven repository so that it would be re-created.
  • I've reinstalled Spring Tool Suite.
  • I've tried asking Eclipse to update the Maven repositories.
  • I've checked for merge conflicts in my local SVN repository. (There are none; this is a brand new branch from trunk that is freshly checked out.)
  • I've checked the Synchronize view in Eclipse to see if it notes any differences. (Eclipse can't get far enough to recognize any projects available to synchronize.)
  • I've searched Google for NullPointerExceptions occurring in VirtualResource.getProjectRelativePaths(). I've found NullPointerExceptions in other very similar places, and I've tried the recommendations for them, just for the heck of it, but none of them work.
  • 我吹走了我的工作区并创建了一个新的工作区。多次。
  • 我已经炸毁了我的 Maven 存储库,以便重新创建它。
  • 我已经重新安装了 Spring Tool Suite。
  • 我试过要求 Eclipse 更新 Maven 存储库。
  • 我已经检查了本地 SVN 存储库中的合并冲突。(没有;这是新签出的主干的全新分支。)
  • 我已经检查了 Eclipse 中的 Synchronize 视图,看它是否注意到任何差异。(Eclipse 无法识别任何可用于同步的项目。)
  • 我在 Google 上搜索了 VirtualResource.getProjectRelativePaths() 中发生的 NullPointerExceptions。我在其他非常相似的地方发现了 NullPointerExceptions,我已经尝试了对它们的建议,只是为了它,但它们都不起作用。

I'm at my wits' end with this problem. Help me, Obi-Wan Kenobi, you are my only hope.

我对这个问题不知所措。帮助我,欧比旺克诺比,你是我唯一的希望。

采纳答案by Robert J. Walker

As echinelli indicated, this did turn out to be an Eclipse (or STS) bug, but installing the latest version isn't the fix, as I already had that version installed. I had installed STS based on Eclipse 4.x; when I uninstalled that and went to the 3.x version, the problem went away.

正如 echinelli 指出的那样,这确实是一个 Eclipse(或 STS)错误,但安装最新版本不是修复程序,因为我已经安装了该版本。我已经安装了基于 Eclipse 4.x 的 STS;当我卸载它并转到 3.x 版本时,问题就消失了。

回答by echinelli

I'm strongly sure that the problem is not related to the maven plugin; but if it is, i was wandering if you run a mvn eclipse:eclipsebefore importing the project into eclipse, if you do that and you are using maven 3, I had checked that maven plugin does not support maven 3 properly yet; so I encourage you to make a mvn eclipse:clean, then import the project as an existing project, and after that activate the maven plugin nature from eclipse. I hope it helps,

我非常确定问题与 maven 插件无关;但如果是这样,如果您mvn eclipse:eclipse在将项目导入 eclipse 之前运行 a,我就会徘徊,如果您这样做并且您正在使用 maven 3,我已经检查过 maven 插件还没有正确支持 maven 3;所以我鼓励你制作一个mvn eclipse:clean,然后将项目作为现有项目导入,然后从 Eclipse 激活 Maven 插件性质。我希望它有帮助,

PS. it seems to be a know eclipse bug (https://www.google.com.uy/search?q=j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModuleVirtualComponent.java&oq=j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModuleVirtualComponent.java&aqs=chrome..69i57.128j0j7&sourceid=chrome&espv=210&es_sm=91&ie=UTF-8); try downloading the last eclipse version; I'm using kepler at work, and I'm working in maven/spring projects and it works fine.

附注。这似乎是一个已知的 Eclipse 错误(https://www.google.com.uy/search?q=j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModuleVirtualComponent.java&oq=j2ee.componentcore.J2EEModuleVirtualComponent.getReferences(J2EEModule&VirtualComponent. ..69i57.128j0j7&sourceid=chrome&espv=210&es_sm=91&ie=UTF-8);尝试下载最新的eclipse版本;我在工作中使用kepler,我在maven/spring项目中工作,它工作正常。

Good luck!

祝你好运!

回答by genjosanzo

This is what I did to fix it:

这是我为修复它所做的:

  1. Removed the project from the workspace
  2. Remove .classpath, .projectand .settingsfolder
  3. Reimport the project
  1. 从工作区中删除了项目
  2. 删除.classpath,.project.settings文件夹
  3. 重新导入项目

回答by Arif Bava

This happens because your m2e plugins are corrupted. To rectify follow the steps below.

发生这种情况是因为您的 m2e 插件已损坏。要纠正,请按照以下步骤操作。

  1. close eclipse
  2. Go to your eclipse workspace folder Under .metadata/pluigns folder, identify all m2e plugins
  3. delete them
  4. copy the relevant plugins from non-corrupted workspace, either from your machine or from any one of your team members machine
  5. restart eclipse
  1. 日食
  2. 转到您的 eclipse 工作区文件夹在 .metadata/plugigns 文件夹下,识别所有 m2e 插件
  3. 删除它们
  4. 从未损坏的工作区复制相关插件,无论是从您的机器还是从您团队成员的任何一台机器
  5. 重启日食

回答by Marc

Ok, I had the same issue with a more obscure reason.

好吧,我遇到了同样的问题,原因更不明。

I used pluginExecutionfor aspectj-maven-pluginand over the course of trying to fix yet another maven issue I had commented out <action><execute><execute></action>

我用pluginExecutionaspectj-maven-plugin,并在我注释掉的试图解决另一个问题行家的过程<action><execute><execute></action>

This leads to the nullpointerexception.

这导致nullpointerexception.

回答by Dino

I solved by adding the <build>section with "maven-compiler-plugin" artifact in the POM. I noticed that without it, Eclipse threw a java.lang.NullPointerException.

我通过<build>在 POM 中添加带有“maven-compiler-plugin”工件的部分来解决。我注意到如果没有它,Eclipse 会抛出一个java.lang.NullPointerException.