Setting Java version for maven build

后端 未结 1 1962
面向向阳花
面向向阳花 2021-01-24 13:41

I am trying to set the java version for a maven build when I execute it from a shell script. Fot some reason it is not picking up the intended java version. Any advise welcome.<

相关标签:
1条回答
  • 2021-01-24 14:10

    I found a solution:

    If I set, this it works. Maven compiles the code.

        <executable>/usr/lib/jvm/jdk-14.0.2/bin/javac</executable>
    

    However, this is not ideal because the path to the install is hard-coded, so on other servers with a different JAVA_HOME location, it won't work. Is it possible to reference $JAVA_HOME from within the POM file? and do something like this?

        <executable><$JAVA_HOME>/bin/javac</executable>
    

    e.g.

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <release>${java.version}</release>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                    <compilerVersion>${java.version}</compilerVersion>
                    <fork>true</fork>
                    <executable>/usr/lib/jvm/jdk-14.0.2/bin/javac</executable>
                </configuration>
            </plugin>
    
    0 讨论(0)
提交回复
热议问题