The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.

故障背景

今天尝试使用maven Jetty插件启动一个war 项目,无论执行maven的任何命令都会提示这样的警告信息。

[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.xingyun:hello-world-sample:war:1.0-SNAPSHOT
[WARNING] The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 

故障分析

根据提示来看,我们可以看出

The expression ${build.finalName} is deprecated. Please use ${project.build.finalName} instead.

也就是说,${build.finalName} 表达式已经过时了,请使用${project.build.finalName}代替。

但是到底应该改哪里呢???

我刚开始找了半天,都没找到到底应该修改哪里。

直到今天晚上,偶然发现了答案,原来在这个地方。。。

<contextPath>/${build.finalName}</contextPath>

之前错误pom.xml 如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!--设置本项目的groupId artifactId 和版本信息-->
    <groupId>com.xingyun</groupId>
    <artifactId>hello-world-sample</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <!-- 设置项目所使用的编码为UTF-8 -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!--设置项目所用JDK版本,也可以使用低版本,建议使用JDK1.8以上版本-->
        <java.version>12</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
        <!--是否跳过测试-->
        <skipTests>true</skipTests>
        <!--设置项目使用第三方依赖包,建议以后都采用这种方式,统一在一个地方声明版本号,这样对项目可以统一管理,方便以后升级-->
        <jetty.maven.plugin.version>9.4.7.v20170914</jetty.maven.plugin.version>
    </properties>

    <build>
        <!-- 定义项目的上下文 -->
        <finalName>hello-world-sample</finalName>
        <!-- 定义插件 -->
        <plugins>
            <!--定义这个插件允许我们使用mvn jetty:run命令运行我们当前这个项目-->
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.maven.plugin.version}</version>
                <configuration>
                    <webApp>
                        <contextPath>/${build.finalName}</contextPath>
                    </webApp>
                    <stopKey>CTRL+C</stopKey>
                    <stopPort>8999</stopPort>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <scanTargets>
                        <scanTarget>src/main/webapp/WEB-INF/web.xml</scanTarget>
                    </scanTargets>
                </configuration>
            </plugin>
            <!--该插件限定Maven 打包时所使用的版本,避免出现版本不匹配问题-->
            <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

修复解决方案

修复成功的pom.xml配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <!--设置本项目的groupId artifactId 和版本信息-->
    <groupId>com.xingyun</groupId>
    <artifactId>hello-world-sample</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <properties>
        <!-- 设置项目所使用的编码为UTF-8 -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!--设置项目所用JDK版本,也可以使用低版本,建议使用JDK1.8以上版本-->
        <java.version>12</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <maven.compiler.plugin.version>3.8.1</maven.compiler.plugin.version>
        <!--是否跳过测试-->
        <skipTests>true</skipTests>
        <!--设置项目使用第三方依赖包,建议以后都采用这种方式,统一在一个地方声明版本号,这样对项目可以统一管理,方便以后升级-->
        <jetty.maven.plugin.version>9.4.7.v20170914</jetty.maven.plugin.version>
    </properties>

    <build>
        <!-- 定义项目的上下文 -->
        <finalName>hello-world-sample</finalName>
        <!-- 定义插件 -->
        <plugins>
            <!--定义这个插件允许我们使用mvn jetty:run命令运行我们当前这个项目-->
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>${jetty.maven.plugin.version}</version>
                <configuration>
                    <webApp>
                        <contextPath>/${project.build.finalName}</contextPath>
                    </webApp>
                    <stopKey>CTRL+C</stopKey>
                    <stopPort>8999</stopPort>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <scanTargets>
                        <scanTarget>src/main/webapp/WEB-INF/web.xml</scanTarget>
                    </scanTargets>
                </configuration>
            </plugin>
            <!--该插件限定Maven 打包时所使用的版本,避免出现版本不匹配问题-->
            <!-- https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.plugin.version}</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Tips:
你有没有好奇过如果不设置<finalName>hello-world-sample</finalName>会发生什么呢?

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

极客星云

谢谢认可,希望对你的学习有帮助

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值