1、可能大家首先想到的就是在pom里加上如下配置就可以了
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
其实不然,在maven官网已经说了这样不能完全保证代码就能运行在jdk7上面
具体参考:
http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html
2、要确保还得加上下面配置
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.14</version>
<configuration>
<signature>
<groupId>org.codehaus.mojo.signature</groupId>
<artifactId>java17</artifactId>
<version>1.0</version>
</signature>
<includeDependencies>true</includeDependencies>
</configuration>
<executions>
<execution>
<id>enforce-java-7</id>
<phase>test</phase>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
上面的配置会检测所编译的class是否能够在jdk7 上面运行
animal-sniffer-maven-plugin 是一个很强大的插件,很好用,你还可以自己做signature,然后用来校验。
具体参考:
http://www.mojohaus.org/animal-sniffer/animal-sniffer-maven-plugin/