目标org.projectlombok执行delombok:lombok-maven-plugin:1.16.10.0:delombok失败:执行org.projectl时缺少必需的类

时间:2017-09-30 18:49:18

标签: java lombok

我正在处理 Lombok 并从链接https://github.com/eugenp/tutorials/tree/master/lombok运行该应用程序,而不对该代码进行任何修改。

当我使用> mvn clean install -DskipTests构建代码时,我收到以下错误,同样 STS 也显示相同的问题是什么?

以下错误供参考?

Execution delombok of goal org.projectlombok:lombok-maven-plugin:1.16.10.0:delombok failed: A required class was missing while executing org.projectlombok:lombok-maven-plugin:1.16.10.0:delombok: com/sun/tools/javac/util/Context
-----------------------------------------------------
realm =    plugin>org.projectlombok:lombok-maven-plugin:1.16.10.0
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/myuser/.m2/repository/org/projectlombok/lombok-maven-plugin/1.16.10.0/lombok-maven-plugin-1.16.10.0.jar
urls[1] = file:/C:/Users/myuser/.m2/repository/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar
urls[2] = file:/C:/Users/myuser/.m2/repository/org/projectlombok/lombok/1.16.10/lombok-1.16.10.jar
urls[3] = file:/C:/Users/myuser/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
Number of foreign imports: 5
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.DirectoryScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import  from realm ClassRealm[project>com.baeldung:lombok:0.1-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

-----------------------------------------------------
 (org.projectlombok:lombok-maven-plugin:1.16.10.0:delombok:delombok:generate-sources)

org.apache.maven.plugin.PluginExecutionException: Execution delombok of goal org.projectlombok:lombok-maven-plugin:1.16.10.0:delombok failed: A required class was missing while executing org.projectlombok:lombok-maven-plugin:1.16.10.0:delombok: com/sun/tools/javac/util/Context
-----------------------------------------------------
realm =    plugin>org.projectlombok:lombok-maven-plugin:1.16.10.0
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/myuser/.m2/repository/org/projectlombok/lombok-maven-plugin/1.16.10.0/lombok-maven-plugin-1.16.10.0.jar
urls[1] = file:/C:/Users/myuser/.m2/repository/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar
urls[2] = file:/C:/Users/myuser/.m2/repository/org/projectlombok/lombok/1.16.10/lombok-1.16.10.jar
urls[3] = file:/C:/Users/myuser/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
Number of foreign imports: 5
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.DirectoryScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import  from realm ClassRealm[project>com.baeldung:lombok:0.1-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

-----------------------------------------------------

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:168)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:331)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1362)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:176)
    at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:112)
    at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:1360)
    at org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:52)
    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:176)
    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:176)
    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:144)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: org.apache.maven.plugin.PluginContainerException: A required class was missing while executing org.projectlombok:lombok-maven-plugin:1.16.10.0:delombok: com/sun/tools/javac/util/Context
-----------------------------------------------------
realm =    plugin>org.projectlombok:lombok-maven-plugin:1.16.10.0
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/Users/myuser/.m2/repository/org/projectlombok/lombok-maven-plugin/1.16.10.0/lombok-maven-plugin-1.16.10.0.jar
urls[1] = file:/C:/Users/myuser/.m2/repository/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar
urls[2] = file:/C:/Users/myuser/.m2/repository/org/projectlombok/lombok/1.16.10/lombok-1.16.10.jar
urls[3] = file:/C:/Users/myuser/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.8/plexus-utils-1.5.8.jar
Number of foreign imports: 5
import: Entry[import org.sonatype.plexus.build.incremental from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.Scanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.DirectoryScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import org.codehaus.plexus.util.AbstractScanner from realm ClassRealm[plexus.core, parent: null]]
import: Entry[import  from realm ClassRealm[project>com.baeldung:lombok:0.1-SNAPSHOT, parent: ClassRealm[maven.api, parent: null]]]

-----------------------------------------------------

    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:166)
    ... 31 more
Caused by: java.lang.NoClassDefFoundError: com/sun/tools/javac/util/Context
    at lombok.delombok.Delombok.<init>(Delombok.java:69)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at java.lang.Class.newInstance(Unknown Source)
    at lombok.launch.Delombok.<init>(Delombok.java:32)
    at lombok.maven.AbstractDelombokMojo.execute(AbstractDelombokMojo.java:135)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
    ... 31 more
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.util.Context
    at java.lang.ClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at lombok.launch.ShadowClassLoader.loadClass(ShadowClassLoader.java:418)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 40 more

enter image description here

1 个答案:

答案 0 :(得分:0)

我刚刚得到了这个问题的解决方案,如下所示。

<强> 1。下载Lombok Jar文件 - 最好在应用程序中使用Maven / Gradle依赖项。可以在此处找到maven依赖项:https://mvnrepository.com/artifact/org.projectlombok/lombok

<强> 2。启动Lombok安装 -
将jar下载到本地存储库后,从命令提示符转到jar位置并运行以下命令java -jar lombok-1.16.18.jar,我们应该受到像这样的lombok提供的Lombok安装窗口的欢迎。

第3。给Lombok安装路径 - 现在点击“Specify Location”按钮,找到eclipse安装文件夹下的eclipse.exe/STS.exe路径。

enter image description here

<强> 4。完成Lombok安装 - 现在我们需要通过单击“安装/更新”按钮最终安装它,我们应该在eclipse中完成安装lombok,我们已经准备好使用它的隐藏功能。最终屏幕看起来像,

enter image description here

<强> 5。请确保在STS.ini文件中添加以下条目(如果尚未存在)。

-vmargs -javaagent:lombok.jar

注意:完成所有这些操作后如果这不起作用,请确保更改工作区并再次构建代码。它会起作用。