ChatGPT解决这个技术问题 Extra ChatGPT

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

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

possibly bump your xstream version?

R
Raghuram

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>

but don't know how to apply that patch
@kasim. Updated answer to indicate how to do this.
Still getting the same error, maven-war-plugin:2.1.1 and Java 7. Any ideas? EDIT: It seems it's fixed for the 'war' goal, not for the 'exploded' goal. jira.codehaus.org/browse/MWAR-279
Problem seen on JRockIt JVM v1.6.0_6-R28.1.4-4.0.1. Resolved by moving to last version of Java 6 JDK from Sun (u45).
By now there is a 2.4 version of maven-war-plugin which solved the problem for me.
S
SebastianH

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.


G
Gilles 'SO- stop being evil'

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.


K
Kresimir Plese

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>

P
Philip Rodrigues

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.


S
Sam Hanley

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.


G
Greg

Apache Maven WAR Plugin 3.0.0 resolved all issues:

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

It doesn't matter if you use jdk 1.6, 1.7 or 1.8


A
A. Rick

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>

r
rkosegi

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>

Thanks, even adding the options helped to cure the build :)
j
jprism

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.


Y
Yogesh Patil

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.


k
krodmannix

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.


S
Sachin Ambalkar

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

(Target folder is where maven puts all compiled code)


R
Rajan Chauhan

I was getting the same error after i upgraded my java version from 8 to some 8.x, i fixed it by going to pom then 1. right click > maven > add plugin 2. type in org.apache.maven and then look for war plugin add it and save, then just clean and install. It should work.


A
A T O M

use this plugin

<plugin>

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

<version>3.2.2</version>

</plugin>

Example pom.xml

pom.xml screenshot`


关注公众号,不定期副业成功案例分享
Follow WeChat

Success story sharing

Want to stay one step ahead of the latest teleworks?

Subscribe Now