【问题标题】:Cannot access defaults field of Properties无法访问属性的默认字段
【发布时间】:2021-07-17 03:51:09
【问题描述】:

我在将应用程序部署到 tomcat 时遇到问题。它以前可以工作,但我格式化了我的电脑并且它停止了工作。

我的 pom.xml:

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<groupId>org.academiadecodigo.javabank</groupId>
<artifactId>javabank-step10-show-delete</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>Java Bank Webapp</name>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>2.21.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-core</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-library</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>4.3.11.RELEASE</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.3.11.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.3.11.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-tx</artifactId>
        <version>4.3.11.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring4</artifactId>
        <version>3.0.8.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.3.6.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-c3p0</artifactId>
        <version>5.3.6.Final</version>
    </dependency>

    <dependency>
        <groupId>org.hibernate.javax.persistence</groupId>
        <artifactId>hibernate-jpa-2.1-api</artifactId>
        <version>1.0.0.Final</version>
    </dependency>

    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <version>1.4.196</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.12</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version> 3.1.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>

    <!-- JSR-301/3 validation -->
    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.2.Final</version>
    </dependency>

</dependencies>

<build>

    <finalName>Java Bank</finalName>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
                <source>1.8</source>
                <target>10</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <url>http://localhost:8080/manager/text</url>
                <server>tomcat</server>
                <path>/javabank</path>
            </configuration>
        </plugin>

    </plugins>
</build>

这是错误:

  1. 注入构造函数时出错,java.lang.ExceptionInInitializerError:无法访问属性的默认字段 在 org.apache.maven.plugin.war.WarMojo.(未知来源) 同时定位 org.apache.maven.plugin.war.WarMojo

我试过了:

https://www.programmersought.com/article/85431846620/

https://www.programmersought.com/article/31114978502/

https://maven.apache.org/plugins/maven-war-plugin/dependency-info.html

删除 .m2 文件夹

“和”stackOverflow 上的所有解决方案

我知道这不是最好的表述问题,但我不知道还能做什么......

【问题讨论】:

  • 我会更新依赖项 - 从 tomcat 版本开始
  • 尝试显式添加maven-war-plugin(参见documentation),因为default binding 已经很旧了。
  • 天哪!这个解决方案与我尝试过的完全一样,但版本不同...... fml......非常感谢!

标签: java spring maven tomcat


【解决方案1】:

我按照Comment by Piotr P. Karwasz 中的说明进行操作。结果很好!我尝试的解决方案之一的问题是版本号。

解决方案: https://maven.apache.org/plugins/maven-war-plugin/plugin-info.html

【讨论】:

    猜你喜欢
    • 2021-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-08
    • 2017-01-26
    • 1970-01-01
    • 2014-03-24
    • 2021-11-17
    相关资源
    最近更新 更多