pom.xml中的maven.compiler.source和maven.compiler.target作用


【形式】

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

【作用】

pom.xml中的maven.compiler.source和maven.compiler.是用來編譯源碼和打包的,通常它們的版本等於系統JDK的大版本,如11,9,8...;

如果不能控制客戶機的jdk,而想讓包的適用性更廣的話,可以手動降低版本號,比如如從11降到8;

如此做了后,在別的機器上運行自己的jar,就不會爆jdk版本低的錯誤。

舉例來說,我之前使用11打了個jar包,放到jdk=9的虛擬機上沒法用,於是手動降低到8,因為代碼中也確實沒用到8后繼版本的特性,於是再次打包后,虛擬機上再運行就可以了。

【在pom中的位置】

這里把maven.compiler.source和maven.compiler.target的位置貼出來,粗體部分就是位置所在。

<?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>org.example</groupId>
    <artifactId>JsonPretty</artifactId>
    <version>1.00</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
            <version>2.6.4</version>
        </dependency>

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

        <dependency>
            <groupId>commons-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.6</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

END


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM