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

jei2mxaa  于 2022-09-20  发布在  Apache
关注(0)|答案(16)|浏览(204)
[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>

当我运行install target以上出现错误时,我如何解决它?

tv6aics1

tv6aics11#

可能正在使用某个版本的maven war plugin,该版本不适用于Java 7?根据this issue(它描述了一个类似的问题),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>
vhipe2zx

vhipe2zx2#

我在做mvn install时遇到了这个问题。我通过先执行mvn clean,然后执行mvn install来解决它。

使用Maven 2.1.1、JDK 1.7.0.45。

1l5u6lss

1l5u6lss3#

已确认:安装了Maven2.x的JDK7将产生此错误。

我使用的是Maven2.2.1和JDK7,并收到了这个错误。我将JDK更改为1.6版,它运行良好。

dwbf0jvd

dwbf0jvd4#

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

ltqd579y5#

确认后,我在Maven 3.0.2和JDK 1.7.0_02上遇到了同样的问题。在运行JDK 1.6.0_30之后,它编译得很好。

ef1yzkbh

ef1yzkbh6#

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

dbf7pr2w

dbf7pr2w7#

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

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

无论您使用的是JDK 1.6、1.7还是1.8

9vw9lbht

9vw9lbht8#

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

两年后,也就是两个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>
6psbrbz9

6psbrbz99#

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

ebdffaop10#

我的EclipseKepler遇到了这个问题。我一搬到4.4时(露娜),就都没了。一定是嵌入了eclipse+maven的问题。

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

6xfqseft

6xfqseft11#

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

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

8nuwlpux

8nuwlpux12#

确保构建路径中的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包。

yqlxgs2m

yqlxgs2m13#

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

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

x7rlezfr

x7rlezfr14#

我得到了相同的错误后,我升级我的Java版本从8到8.x,我修复了它转到pom然后1。右击>maven>添加插件2。输入org.apache.maven,然后查找WAR插件添加它并保存,然后只需清理和安装。应该能行得通。

w41d8nur

w41d8nur15#

使用此插件

<plugin>

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

<version>3.2.2</version>

</plugin>

示例pom.xml

pom.xml screenshot`

相关问题