Reputation: 37
Below I describe more about the issue I have. I know there are other threads in Stackoverflow but my issue is not resolvded yet, hence I have tested most of the suggestions.
Description I making a program using Spring REST Interface (see code below) and I have problem to compile code with Maven (see problem section). I have no problem to compile the code using my IDE Eclipse.
Problem When I compile my code with Maven in command line in Windows: mvn clean compile I get the fault message: error: invalid target release: 1.17. Maven and the Java are having the latest versions and the env. varible JAVA_HOME is set to correct Java installationpath: C:>echo %JAVA_HOME% C:\Program Files\Java\jdk-17.0.1
C:>java -version java version "17.0.1" 2021-10-19 LTS Java(TM) SE Runtime Environment (build 17.0.1+12-LTS-39) Java HotSpot(TM) 64-Bit Server VM (build 17.0.1+12-LTS-39, mixed mode, sharing)
C:>mvn -version Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537) Maven home: C:\tobbe\apache-maven-3.8.4 Java version: 17.0.1, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-17.0.1 Default locale: sv_SE, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
I have tried several different versions of both Java and Maven but with same error. I have reduced source/target in POM and I get the same fault when versions are between 11-17 and lower version gives souce code compilation fault because probably version is to low.
Here is my 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>tobbe</groupId>
<artifactId>stocks-rest</artifactId>
<packaging>jar</packaging>
<version>1.0.1-SNAPSHOT</version>
<properties>
<java.version>17</java.version>
<maven.compiler.source>1.17</maven.compiler.source>
<maven.compiler.target>1.17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>tobbe</groupId>
<artifactId>Stocks_Backend</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>
And my code:
/**
* Version 1.0.2
*/
package Rest;
import java.awt.AWTException;
import java.awt.HeadlessException;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.lang.instrument.IllegalClassFormatException;
import java.net.MalformedURLException;
import java.util.List;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import Enums.Market;
import Enums.REA_Stock_State;
import Enums.Stock_State;
import REA.REAMain;
import REA.REAStock;
import Stocks.Logger;
import mExceptions.ElementSizeException;
@SpringBootApplication
@RestController
public class StocksRestApi
{
private Logger iLogger = null;
public StocksRestApi()
{
iLogger = new Logger();
}
public static void main(String[] args)
{
SpringApplication.run(StocksRestApi.class, args);
}
@GetMapping(value="/logdata")
public String logdata()
{
List<String> dataLogList = iLogger.getLogData();
String dataLog = "";
if(dataLogList.size() == 0)
{
dataLog = "Run http://localhost:8080/rea first";
}
for(String row: dataLogList)
{
dataLog += row;
}
return dataLog;
}
}
Question Why do I get invalid target release 1.17 when I compile my code with Maven?
Upvotes: 0
Views: 4453
Reputation: 201447
Because there is no Java 1.17 release. They stopped putting 1
in front of version numbers. It was confusing. So they stopped with Java 9 (see also JEP223). Use
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
Upvotes: 7