执行 org.apache.maven.plugins:maven-war-plugin:2.1.1:war 时缺少必需的类
Posted
技术标签:
【中文标题】执行 org.apache.maven.plugins:maven-war-plugin:2.1.1:war 时缺少必需的类【英文标题】:A required class was missing while executing org.apache.maven.plugins:maven-war-plugin:2.1.1:war 【发布时间】:2013-08-28 20:40:48 【问题描述】:这是我的全新安装 -x 结果:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building test Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test ---
[INFO] Deleting C:\Users\utopcu\workspace\test\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test ---
[WARNING] Using platform encoding (Cp1254 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ test ---
[WARNING] Using platform encoding (Cp1254 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\utopcu\workspace\test\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ test ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ test ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.1.1:war (default-war) @ test ---
[WARNING] Error injecting: org.apache.maven.plugin.war.WarMojo
java.lang.NoClassDefFoundError: org/apache/maven/shared/filtering/MavenFilteringException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483)
at java.lang.Class.getDeclaredConstructors(Class.java:1891)
at com.google.inject.spi.InjectionPoint.forConstructorOf(InjectionPoint.java:245)
at com.google.inject.internal.ConstructorBindingImpl.create(ConstructorBindingImpl.java:99)
at com.google.inject.internal.InjectorImpl.createUninitializedBinding(InjectorImpl.java:653)
at com.google.inject.internal.InjectorImpl.createJustInTimeBinding(InjectorImpl.java:863)
at com.google.inject.internal.InjectorImpl.createJustInTimeBindingRecursive(InjectorImpl.java:790)
at com.google.inject.internal.InjectorImpl.getJustInTimeBinding(InjectorImpl.java:278)
at com.google.inject.internal.InjectorImpl.getBindingOrThrow(InjectorImpl.java:210)
at com.google.inject.internal.InjectorImpl.getProviderOrThrow(InjectorImpl.java:986)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1019)
at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:982)
at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1032)
at org.eclipse.sisu.reflect.AbstractDeferredClass.get(AbstractDeferredClass.java:44)
at com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:86)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.provision(InternalFactoryToInitializableAdapter.java:55)
at com.google.inject.internal.ProviderInternalFactory$1.call(ProviderInternalFactory.java:70)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:100)
at org.eclipse.sisu.plexus.lifecycles.PlexusLifecycleManager.onProvision(PlexusLifecycleManager.java:134)
at com.google.inject.internal.ProvisionListenerStackCallback$Provision.provision(ProvisionListenerStackCallback.java:109)
at com.google.inject.internal.ProvisionListenerStackCallback.provision(ProvisionListenerStackCallback.java:55)
at com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:68)
at com.google.inject.internal.InternalFactoryToInitializableAdapter.get(InternalFactoryToInitializableAdapter.java:47)
at com.google.inject.internal.InjectorImpl$2$1.call(InjectorImpl.java:997)
at com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1047)
at com.google.inject.internal.InjectorImpl$2.get(InjectorImpl.java:993)
at com.google.inject.Scopes$1$1.get(Scopes.java:59)
at org.eclipse.sisu.locators.LazyBeanEntry.getValue(LazyBeanEntry.java:82)
at org.eclipse.sisu.plexus.locators.LazyPlexusBean.getValue(LazyPlexusBean.java:52)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:259)
at org.codehaus.plexus.DefaultPlexusContainer.lookup(DefaultPlexusContainer.java:251)
at org.apache.maven.plugin.internal.DefaultMavenPluginManager.getConfiguredMojo(DefaultMavenPluginManager.java:459)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:97)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:318)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:414)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:357)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: java.lang.ClassNotFoundException: org.apache.maven.shared.filtering.MavenFilteringException
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:244)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:230)
... 55 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.342s
[INFO] Finished at: Mon Aug 26 14:09:27 EEST 2013
[INFO] Final Memory: 11M/105M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project test: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war failed: A required class was missing while executing org.apache.maven.plugins:maven-war-plugin:2.1.1:war: org/apache/maven/shared/filtering/MavenFilteringException
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.apache.maven.plugins:maven-war-plugin:2.1.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/C:/Users/utopcu/.m2/repository/org/apache/maven/plugins/maven-war-plugin/2.1.1/maven-war-plugin-2.1.1.jar
[ERROR] urls[1] = file:/C:/Users/utopcu/.m2/repository/org/apache/maven/reporting/maven-reporting-api/2.0.6/maven-reporting-api-2.0.6.jar
[ERROR] urls[2] = file:/C:/Users/utopcu/.m2/repository/org/apache/maven/doxia/doxia-sink-api/1.0-alpha-7/doxia-sink-api-1.0-alpha-7.jar
[ERROR] urls[3] = file:/C:/Users/utopcu/.m2/repository/commons-cli/commons-cli/1.0/commons-cli-1.0.jar
[ERROR] urls[4] = file:/C:/Users/utopcu/.m2/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
[ERROR] urls[5] = file:/C:/Users/utopcu/.m2/repository/org/apache/maven/maven-archiver/2.4.1/maven-archiver-2.4.1.jar
[ERROR] urls[6] = file:/C:/Users/utopcu/.m2/repository/org/codehaus/plexus/plexus-archiver/1.2/plexus-archiver-1.2.jar
[ERROR] urls[7] = file:/C:/Users/utopcu/.m2/repository/org/codehaus/plexus/plexus-io/1.0.1/plexus-io-1.0.1.jar
[ERROR] urls[8] = file:/C:/Users/utopcu/.m2/repository/org/codehaus/plexus/plexus-interpolation/1.13/plexus-interpolation-1.13.jar
[ERROR] urls[9] = file:/C:/Users/utopcu/.m2/repository/junit/junit/3.8.1/junit-3.8.1.jar
[ERROR] urls[10] = file:/C:/Users/utopcu/.m2/repository/com/thoughtworks/xstream/xstream/1.3.1/xstream-1.3.1.jar
[ERROR] urls[11] = file:/C:/Users/utopcu/.m2/repository/xpp3/xpp3_min/1.1.4c/xpp3_min-1.1.4c.jar
[ERROR] urls[12] = file:/C:/Users/utopcu/.m2/repository/org/codehaus/plexus/plexus-utils/2.0.5/plexus-utils-2.0.5.jar
[ERROR] urls[13] = file:/C:/Users/utopcu/.m2/repository/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.jar
[ERROR] Number of foreign imports: 1
[ERROR] import: Entry[import from realm ClassRealm[maven.api, parent: null]]
[ERROR]
[ERROR] -----------------------------------------------------: org.apache.maven.shared.filtering.MavenFilteringException
[ERROR] -> [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/PluginContainerException
这是我的 pom.xml:
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>trest</groupId>
<artifactId>test</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>test Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
</plugin>
</plugins>
</build>
</project>
我尝试删除存储库并重新安装。我总是收到这个错误。看来我需要帮助。我认为我的 mojo 插件坏了,但我重新安装了几次。有什么建议吗?
【问题讨论】:
您使用哪个 Maven 版本?你怎么称呼maven?我用 Maven 3.0.5、3.1、2.2.1 检查了同一个 pom,它没有任何问题。您是否清理了本地存储库并重试了? 刚刚清除~/.m2/repository/org/liquibase
为我解决了这个问题。
【参考方案1】:
org.apache.maven.shared.filtering.MavenFilteringException
类是否存在于 file:/C:/Users/utopcu/.m2/repository/org/apache/maven/shared/maven-filtering/1.0-beta-2/maven-filtering-1.0-beta-2.jar
中?
错误消息表明它没有。也许 JAR 以某种方式损坏了。
我也想知道1.0-beta-2
的版本来自哪里;我的磁盘上有1.0
。试试 WAR 插件的 2.3
版本。
【讨论】:
我之前已经检查过几次它是否已损坏或不存在。没有问题。但是,当您回答我的问题时,它变得神奇地损坏了:) 感谢您解决 btw。 我发现一个类似的问题是一罐已经损坏的思想作品。从 m2 文件夹中删除 jar 并再次执行 mvn clean install。在那之后它起作用了。构建成功【参考方案2】:尝试删除 ~/.m2/repository/org/apache/maven 中的 maven 文件夹并再次构建您的项目以强制下载 maven 库。上次我遇到这个 java.lang.NoClassDefFoundError: org/apache/maven/shared/filtering/MavenFilteringException 时,这对我有用。
【讨论】:
【参考方案3】:这应该可以修复错误
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-filtering</artifactId>
<version>1.3</version>
</dependency>
</dependencies>
</plugin>
【讨论】:
【参考方案4】:遇到同样的问题并通过将我的 Maven 从 3.0.4 升级到 3.1.1 来解决。请尝试使用 v3.1.1 或更高版本(如果有)
【讨论】:
谢谢。我遇到了同样的问题并通过将我的 Maven 升级到 3.1.1 解决了 谢谢。将 maven 版本从 3.0.4 升级到 3.2.3 对我有用。 在尝试了其他答案之后,这也对我有用。非常感谢。【参考方案5】:您应该在 pom.xml 文件中添加 maven-resources-plugin。删除 ~/.m2/repository 并不总是有效。
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
现在再次构建您的项目。应该会成功!
【讨论】:
【参考方案6】:在将缺少的版本标记添加到 maven-war-plugin 后,这也发生在我身上(不确定默认使用的是什么版本,我更改为最新的,在我的情况下为 2.6)。我必须擦除 .m2/repository 才能让构建再次成功。
我首先尝试清理 maven-filtering 文件夹(在 repo 中),但后来我得到的是 ArchiverException 而不是 MavenFilterException。 所以我得出结论,本地存储库已损坏(用于版本升级?),我删除了所有内容。
这为我解决了问题。只需清理您的本地存储库。
【讨论】:
【参考方案7】:确保您的 Java 版本符合项目的 Java 版本要求。这可能是此类问题的另一个原因。
【讨论】:
这是我的问题。项目中的 pom 没有指定 maven 版本,我的机器上安装了许多 java 版本,最新的是默认版本。所以我的 Maven 使用的是 JDK 13,但该项目需要 8 个。这对我有帮助 ***.com/a/43524685/4775820【参考方案8】:以下我的解决方案适用于无法访问默认 maven 存储库的情况(例如,由于防火墙)。
如果无法访问默认存储库,则必须在 settings.xml 中指定适当的本地 <pluginRepository>
。如果它与您的本地工件存储库相同,则仍需要将其添加到 <pluginRepositories>
部分才能找到插件 jar。常规 <repositories>
部分不用于获取插件 jar。
然而,就我而言,问题是由于该部分中定义了多个插件存储库这一事实引起的。
列表中的第一个存储库不包含所需的 maven-filtering jar。
我必须更改 <pluginRepository>
定义的顺序以确保第一个包含 maven-filtering。
更改存储库定义通常需要清理 ~/.m2/repository 并重新开始。
【讨论】:
【参考方案9】:就我而言,情况是这样的:我有一个离线服务器,我必须在其上执行构建。为此,我先在本地编译了所有内容,然后将存储库文件夹转移到离线服务器。
问题 - 构建可以在本地工作,但不能在服务器上工作,即使他们都有相同的 maven 版本、相同的存储库文件夹、相同的 JDK。
原因:在我的本地机器上,我在 settings.xml 中有额外的自定义“”条目。当我将相同内容添加到服务器上的 settings.xml 时,我的问题就消失了。
【讨论】:
以上是关于执行 org.apache.maven.plugins:maven-war-plugin:2.1.1:war 时缺少必需的类的主要内容,如果未能解决你的问题,请参考以下文章