[英]How to force Maven to target Java 1.7 with a javax.persistence dependency?
I am setting this in the pom.xml file: 我在pom.xml文件中设置此设置:
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
</plugin>
</plugins>
</build>
When I open the .jar file and check the .class file with javap -v, it outputs "major version: 52" which corresponds to 1.8, so I see it did not respect my configuration. 当我打开.jar文件并使用javap -v检查.class文件时,它输出对应于1.8的“主要版本:52”,因此我发现它不遵守我的配置。
I have a dependency on javax.persistence: 我对javax.persistence有依赖性:
<dependencies>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>
If I remove this dependency, the javap -v outputs "major version: 51" which is the target I want. 如果删除此依赖项,则javap -v输出“主要版本:51”,这是我想要的目标。
But I need the dependency. 但是我需要依赖。
Is it possible to target 1.7 with the javax.persistence dependency? 是否可以使用javax.persistence依赖关系来定位1.7? How? 怎么样?
I was expecting compilation errors if it could not target Java 1.7 as I configured. 如果它不能像我配置的那样针对Java 1.7,我期待编译错误。
I am using IntelliJ IDEA. 我正在使用IntelliJ IDEA。
Thanks. 谢谢。
Did you try this? 你有尝试过吗?
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.