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

[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> 

当我运行安装目标上面的错误发生时,我该如何解决它?

也许是一个版本的Maven战争插件正在使用,这不适用于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> 

在进行mvn install时,我遇到了这个问题。 我首先做了一个mvn clean ,然后是mvn install

使用maven 2.1.1,JDK 1.7.0.45。

确认:JDK7和Maven 2.x会产生这个错误。

我正在使用Maven 2.2.1和JDK7,并得到这个错误。 我将JDK更改为1.6版,工作正常。

而不是改变JDK版本和Maven版本,试试这个:

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

确认,我碰到与maven 3.0.2和jdk 1.7.0_02相同的问题。 在运行jdk 1.6.0_30后,编译得很好。

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

如果您使用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> 

这绝对看起来与不兼容的插件,库和语言版本有关。

两年以及两个Java版本之后,我在Spring和Hibernate上的旧书中做了一个示例项目时也遇到了同样的错误。

我能够通过注释掉apache.maven.plugins的所有版本标签并将Java版本设置为1.8来解决错误。 这让我知道什么是最新的和最好的版本的库,与Maven的一些警告的成本缺less版本标签。 如果您关心警告,可以将版本标签设置为最新版本,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> 

确保在Buildpath中具有JDK版本,并且源标记中指定的版本匹配相同。

 <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> ` 

当我在源代码中将版本更正为1.7时,我的构buildpath指向源代码中的jdk 1.7和“1.6”,问题得到解决。

执行mnv clean和mvn包。

我的日食开普勒有这个问题。 只要我搬到4.4(月神),一切都消失了。 必须是eclipse + mavenembedded式的问题

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

对于我改变的插件版本不能解决问题,改变的JDK版本不在我的控制之下。

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

尝试删除所有的caching。 当我删除目标文件夹,它工作正常。

(目标文件夹是Maven放置所有编译代码的地方)