JDK的许多版本:如何指定使用哪一个? [英] Many versions of JDK: How do I specify which one is used?

查看:450
本文介绍了JDK的许多版本:如何指定使用哪一个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了JDK中的许多版本: 1.4.2,1.5和1.6
如何指定使用Ant编译时使用JDK的哪一个版本?

I have installed many versions of the JDK: 1.4.2, 1.5 and 1.6. How do I specify which version of the JDK is used when compiling using Ant?

推荐答案

有两种解决方案:


  • 指定在您的命令的完整路径:
    例如的/ opt / JAVA / jdk16 /斌/ javac的... 在Linux

  • 使用javac命令的 -source -target 参数。这允许您指定源$ C ​​$ C级和有针对性的JRE版本

  • Specify the full path in your command: for example /opt/java/jdk16/bin/javac ... on Linux
  • Use the -source and -target arguments of the javac command. This allows you specify the source code level and targeted JRE version

另外请注意:


  • 一些Linux发行版可​​以包括工具指定默认情况下要使用的JDK版本。

  • 使用 -source -target checkes你的语言结构符合目标运行,但不检查核心类是兼容的。这意味着,与 String.isEmpty()编译-source 1.4 在JDK 1.6会就好了,即使你使用这似乎在Java中6,这可能会在运行时会导致错误

  • Some Linux distributions can include tools to specify which JDK version to use by default.
  • Using -source and -target checkes that your language constructs are compliant with the targeted runtime, but does NOT check that core classes are compatible. This means that compiling with -source 1.4 on a JDK 1.6 will be just fine, even if you use String.isEmpty() which appeared in Java 6. This might lead to errors at runtime

这篇关于JDK的许多版本:如何指定使用哪一个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆