Cannot construct org.apache.maven.plugin.war.util.WebappStructure as it does not have a no-args constructor

匿名 (未验证) 提交于 2019-12-03 02:44:02

问题:

[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 compiler Plugin:

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

when i run install target above error occurs, how can i resolve it?

回答1:

Perhaps a version of maven war plugin is being used, which does not work with Java 7? As per this issue (which describes a similar problem), 2.1.1 version of maven war plugin should work.

Include the following in your pom.xml

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


回答2:

I had this problem when doing a mvn install. I resolved it by doing a mvn clean first, followed by a mvn install.

Using maven 2.1.1, JDK 1.7.0.45.



回答3:

It's confirmed: JDK7 with Maven 2.x will produce this error.

I am using Maven 2.2.1 and JDK7 and got this error. I changed the JDK to version 1.6 and it's working fine.



回答4:

Instead of changing JDK versions and Maven versions, try this:

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


回答5:

Confirmed, I ran into the same issue with maven 3.0.2 and jdk 1.7.0_02. After running against jdk 1.6.0_30 it compiled just fine.



回答6:

I don't think the version was the problem. I solved deleting my target folder (because it contains webapp-cache.xml) and doing Maven install again.



回答7:

if your using jdk 1.6 kindly add this plugin entry to your 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> 


回答8:

This definitely seems to be related to incompatible plugin, library and language versions.

Two years, and two Java versions later, I had this same error while doing a sample project from an older book on Spring and Hibernate.

I was able to resolve the error by commenting out all of the version tags for the apache.maven.plugins and setting the Java version to 1.8. This let me know what was the latest and greatest version of the libraries, with the cost of some warnings from Maven about missing the version tags. If you care about the warnings, you can set the version tags to be latest version and the warnings from Maven should go away.

I executed mvn clean package and then just 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> 


回答9:

For me changing plugin version could not solve problme and changing JDK version is not in my control.

However running mvn clean before mvn tomcat6:deploy solved this problem.



回答10:

Make sure to have the JDK version in your Build path and the version specified in the source tag match the same.

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

I had the build path pointing to jdk 1.7 and "1.6" in the source tag, when I corrected the version to 1.7 in source tag the issue got resolved.

Execute mnv clean and mvn package.



回答11:

I had this problem with my eclipse Kepler. As soon as I moved to 4.4 (Luna) , all gone. Must be an issue with eclipse + maven embedded

I tried both JDK 1.7 and 1.8. No difference.



回答12:

Try to delete all your cache. When i deleted target folder, it works fine.

(Target folder is where maven puts all compiled code)



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!