我使用maven来构建我的项目。
我有以下配置:
D:\ freelance \ polyndrom> mvn -verion Apache Maven 3.2.3 (33f8c3e1027c3ddde99d3cdebad2656a31e8fdf4; 2014-08-12T00:58:1 0 + 04:00) Maven home:C:\ Program Files \ apache \ apache-maven-3.2.3 Java版本: 1.8.0_25,供应商:Oracle Corporation Java home:C:\ Program Files \ Java \ jdk1.8.0_25 \ jre默认语言环境:ru_RU,平台编码: Cp1251操作系统名称:" Windows 7",版本:" 6.1",arch:" amd64",系列: " DOS"
但是当我编译项目时,我看到以下错误:
<?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>polyndrom</groupId>
<artifactId>polyndrom</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.8.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.peterservice.polyndrom.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
我很困惑 - 我看到我使用java 8。
的pom.xml:
this.jdbcTemplate.update(
"call SUPPORT.REFRESH_ACTORS_SUMMARY(?)",
Long.valueOf(unionId));
答案 0 :(得分:66)
默认情况下,Maven假设您使用JDK 1.5编写代码并且要编译到同一目标。您需要将maven-compiler-plugin添加到构建插件中,以告诉它使用1.8。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
查看插件的文档以获取更多信息:http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html
答案 1 :(得分:3)
您可以在属性中指定语言版本
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
答案 2 :(得分:0)