无法构建org.apache.maven.plugin.war.util.WebappStructure,因为它没有无参数的构造函数


92
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor
---- Debugging information ----
message             : Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor
cause-exception     : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message       : Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor
class               : org.apache.maven.plugin.war.util.WebappStructure
required-type       : org.apache.maven.plugin.war.util.WebappStructure
path                : /webapp-structure
line number         : 1
-------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Trace
com.thoughtworks.xstream.converters.ConversionException: Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor
---- Debugging information ----
message             : Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor
cause-exception     : com.thoughtworks.xstream.converters.reflection.ObjectAccessException
cause-message       : Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor
class               : org.apache.maven.plugin.war.util.WebappStructure
required-type       : org.apache.maven.plugin.war.util.WebappStructure
path                : /webapp-structure
line number         : 1
-------------------------------
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:63)
    at com.thoughtworks.xstream.core.AbstractReferenceUnmarshaller.convert(AbstractReferenceUnmarshaller.java:45)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convertAnother(TreeUnmarshaller.java:46)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.start(TreeUnmarshaller.java:117)
    at com.thoughtworks.xstream.core.ReferenceByXPathMarshallingStrategy.unmarshal(ReferenceByXPathMarshallingStrategy.java:29)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:846)
    at com.thoughtworks.xstream.XStream.unmarshal(XStream.java:833)
    at com.thoughtworks.xstream.XStream.fromXML(XStream.java:781)
    at org.apache.maven.plugin.war.util.WebappStructureSerializer.fromXml(WebappStructureSerializer.java:73)
    at org.apache.maven.plugin.war.AbstractWarMojo.buildWebapp(AbstractWarMojo.java:404)
    at org.apache.maven.plugin.war.AbstractWarMojo.buildExplodedWebapp(AbstractWarMojo.java:375)
    at org.apache.maven.plugin.war.WarMojo.performPackaging(WarMojo.java:181)
    at org.apache.maven.plugin.war.WarMojo.execute(WarMojo.java:143)
    at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:535)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348)
    at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
    at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
    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:601)
    at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
    at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
    at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
    at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: com.thoughtworks.xstream.converters.reflection.ObjectAccessException: Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor
    at com.thoughtworks.xstream.converters.reflection.PureJavaReflectionProvider.newInstance(PureJavaReflectionProvider.java:59)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.instantiateNewInstance(AbstractReflectionConverter.java:257)
    at com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter.unmarshal(AbstractReflectionConverter.java:124)
    at com.thoughtworks.xstream.core.TreeUnmarshaller.convert(TreeUnmarshaller.java:56)
    ... 31 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Sat Sep 24 17:25:45 CEST 2011
[INFO] Final Memory: 15M/37M
[INFO] ------------------------------------------------------------------------

JDK:1.7

Maven编译器插件:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
</plugin>

当我运行以上安装目标错误时,如何解决?


可能会破坏您的xstream版本?
rogerdpack

Answers:


136

也许正在使用的Maven War插件版本与Java 7不兼容?根据此问题(描述了类似的问题),2.1.1 maven war插件的版本应该可以工作。

在pom.xml中包含以下内容

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
</plugin>

但不知道如何应用该补丁
TechFind 2011年

@kasim。更新了答案以指示如何执行此操作。
拉古拉姆

仍然遇到相同的错误,maven-war-plugin:2.1.1和Java7。有什么想法吗?编辑:看来它是为“战争”目标而不是为“爆炸”目标而固定的。jira.codehaus.org/browse/MWAR-279
BrunoJCM 2013年

在JRockIt JVM v1.6.0_6-R28.1.4-4.0.1上看到的问题。通过从Sun(u45)移至Java 6 JDK的最新版本来解决。
8bitjunkie 2014年

4
到目前为止,有一个2.4版本的maven-war-plugin为我解决了这个问题。
本杰明·塞勒

16

我做一个时遇到了这个问题mvn install。我先解决了问题mvn clean,然后再解决了mvn install

使用maven 2.1.1,JDK 1.7.0.45。


9

已确认:带有Maven 2.x的JDK7将产生此错误。

我正在使用Maven 2.2.1和JDK7并收到此错误。我将JDK更改为1.6版,并且运行良好。


8

代替更改JDK版本和Maven版本,请尝试以下操作:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
    <version>2.3.2</version>
</plugin>

5

确认,我遇到了与Maven 3.0.2和jdk 1.7.0_02相同的问题。在针对jdk 1.6.0_30运行之后,它编译就很好了。


4

我认为版本不是问题。我解决了删除目标文件夹(因为它包含webapp-cache.xml)并再次进行Maven安装的问题。


4

Apache Maven WAR插件3.0.0解决了所有问题:

<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>

使用jdk 1.6、1.7或1.8都没关系


2

如果您使用的是jdk 1.6,请将此插件条目添加到pom.xml中

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <compilerArgument>-Xlint:all</compilerArgument>
        <showWarnings>true</showWarnings>
        <showDeprecation>true</showDeprecation>
    </configuration>
</plugin>

谢谢,甚至添加选项也有助于解决问题:)
Guido U. Draheim 2014年

2

这显然与不兼容的插件,库和语言版本有关。

两年之后,又有两个Java版本,我在做一本关于Spring和Hibernate的旧书中的示例项目时遇到了相同的错误。

通过注释掉apache.maven.plugins的所有版本标签并将Java版本设置为1.8,可以解决该错误。这让我知道什么是最新和最好的库版本,以及Maven关于缺少版本标签的一些警告的代价。如果您关心警告,则可以将版本标签设置为最新版本,Maven的警告应该消失。

我执行了mvn clean package,然后执行mvn package

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-war-plugin</artifactId>
<!-- <version>2.1-beta-1</version> -->
</plugin>
<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-compiler-plugin</artifactId>
<!-- <version>2.1</version> -->
     <configuration>
          <source>1.8</source>
          <target>1.8</target>
     </configuration>
</plugin>

2

我的日食开普勒遇到了这个问题。我移到4.4(Luna)后,一切都消失了。Eclipse + Maven嵌入式肯定是一个问题

我同时尝试了JDK 1.7和1.8。没有不同。


1

对我来说,更改插件版本无法解决问题,并且更改JDK版本不在我的控制范围内。

但是运行mvn clean之前mvn tomcat6:deploy解决了这个问题。


0

确保Build路径中的JDK版本与source标记中指定的版本匹配。

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.1</version>
    <configuration>
     **<source>1.7</source>**
       <target>1.7</target>
       <debug>true</debug>
    </configuration>
</plugin> `

我在源代码标签中指向jdk 1.7和“ 1.6”的构建路径,当我在源代码标签中将版本更正为1.7时,此问题已解决。

执行mnv clean和mvn软件包。



0

我将Java版本从8升级到8.x后,出现了同样的错误,我先通过pom然后1修复了它。右键单击> maven>添加插件2.键入org.apache.maven,然后寻找war插件添加并保存,然后清理并安装。它应该工作。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.