JDK7交叉编译

要解决的问题

用JDK7编译出能在JRE6里头运行的class文件

Maven Compiler Plugin

(Maven Compiler Plugin)[http://maven.apache.org/plugins/maven-compiler-plugin/]

Merely setting the target option does not guarantee that your code actually runs on a JRE with the specified version. The pitfall is unintended usage of APIs that only exist in later JREs which would make your code fail at runtime with a linkage error. To avoid this issue, you can either ** configure the compiler's boot classpath to match the target JRE **or **use the Animal Sniffer Maven Plugin to verify your code doesn't use unintended APIs **

来源: http://maven.apache.org/plugins/maven-compiler-plugin/examples/set-compiler-source-and-target.html

仅仅去设定target的值并不能保证你的程序可以在更低版本的jre上面运行,因为这个只是language level上面的保证。

解决思路

  1. 用RT.JAR去验证
<compilerArguments>
    <bootclasspath>xxxxxxxxx</bootclasspath>
</compilerArguments>

这个还能叫做交叉编译,用其他的JRE去验证

  1. 直接用别的版本的JAVAC去编译 examples/compile-using-different-jdk.html
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
        <verbose>true</verbose>
        <fork>true</fork>
        <executable>${jdk6.home}/bin/javac</executable>
        <compilerVersion>1.6</compilerVersion>
    </configuration>
</plugin>

问题是这就不是交叉编译了。。。

想要检查最后出来的字节文件是什么版本的java字节码

javap -verbose jp.co.worksap.updater.api.ServerType | grep major

转载于:https://my.oschina.net/zuoyc/blog/375282

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值