如何使用不同的JRE版本来编译和构建项目呢? [英] How Can I Tell Eclipse to Compile and Build a Project with a Different JRE Version than it Normally Does?

查看:439
本文介绍了如何使用不同的JRE版本来编译和构建项目呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这个问题是否已经全部得到回答,或者如果我的标题是足够的描述性的,因为我的情况,但是我被要求将一个项目从Ant构建到Maven。那部分并不是太糟糕了,但是我被告知这个应用程序是专为JRE版本1.5设计的,而不是JRE 6我一直在处理的一切。现在,我对Eclipse和Java本身非常新颖,所以当我被要求告诉Eclipse或Maven使用JRE 1.5来构建这个特定的项目时,我有点困惑。我已经安装了,我已经尝试按照这里列出的步骤:( Eclipse:构建并符合不同的JRE版本),但我遇到了一个障碍。



我已经设法改变运行配置以使用备用JRE jre1.5.0_11。当我尝试构建它时,控制台会弹出以下内容:

  [错误]无法找到Javac编译器: 
[错误] C:\程序文件(x86)\Java\jre1.5.0_11\..\lib\tools.jar
[错误]请确保您使用的是JDK 1.4或以上,
[ERROR]不是JRE(需要com.sun.tools.javac.Main类)。
[ERROR]在大多数情况下,您可以通过设置JAVA_HOME环境变量来更改Java
[ERROR]安装的位置。

我假设这意味着我需要使用JDK 1.5才能使用JRE 1.5,因为我目前正在使用JDK 1.6。现在,有没有办法安装JDK 1.5,以便这个项目可以使用它?我的JAVA_HOME变量目前指向JDK 1.6,我希望它能够保持这种方式...有一种方法可以使用两者,只需要告诉项目(或Eclipse或Maven ...但是它的工作原理)使用特定版本的JDK?

解决方案

是的,这是可能的。您可以随意安装不同版本的Java - JRE和JDK,并告诉Eclipse每个项目使用哪一个。



第一步是安装您的机器上的JDK 1.5(JDK是Java [SE]开发套件的缩写,在Oracle下载站点上查找)。 JDK包括一个JRE,所以为了让生活变得更简单,你通常可以安装JDK,而不用担心JRE / JDK的区别。



第二步是告诉Eclipse新的JDK。转到首选项... ,然后再使用Java > 安装的JRE 。单击搜索... 按钮,Eclipse应该找到您刚刚安装的JDK 1.5并将其添加到列表中。



最后一步是分配那个JDK 1.5到你的项目。打开项目的属性菜单(右键单击它)。然后设置这些值:




  • Java编译器选项卡

    • 勾选启用项目特定设置

    • 编译器合规级别设置为 1.5


  • Java构建路径选项卡,子选项卡

    • 查找 JRE系统库项目,点击编辑...

    • 替代JRE 设置为您刚刚安装的JDK 1.5



I'm not sure if this question has been answered in full or if my title is descriptive enough given my situation, but I've been asked to convert a project from being built with Ant to Maven. That part isn't too bad, but I've been told that this application was designed specifically for the JRE version 1.5 rather than the JRE 6 everything else I've been dealing with uses. Now, I'm incredibly new to Eclipse and Java themselves, so I was a bit confused when I was asked to tell either Eclipse or Maven to build this particular project using the JRE 1.5 instead. I have it installed, I believe, and I've tried to follow the steps outlined here: ( Eclipse: Build and conform to different JRE versions ), but I've run into a snag.

I've managed to change the Run Configuration to use the Alternate JRE jre1.5.0_11. When I then tried to build it, the console spat out the following:

[ERROR] Unable to locate the Javac Compiler in:
[ERROR] C:\Program Files (x86)\Java\jre1.5.0_11\..\lib\tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.

I assume this means that I need to be using the JDK 1.5 in order to use the JRE 1.5, since I'm currently working with JDK 1.6. Now, is there a way to install the JDK 1.5 so that this project can use it? My JAVA_HOME variable currently points to the JDK 1.6, and I would like it to stay that way... Is there a way to be able to use both and simply tell the project (or Eclipse or Maven... however it works) to use a specific version of the JDK?

解决方案

Yes, this is possible. You can install as many different versions of Java — JREs and JDKs — as you like, and tell Eclipse which one to use for each project.

First step is to install the JDK 1.5 on your machine (JDK is short for 'Java [SE] Development Kit', look for that on the Oracle download site). The JDK includes a JRE, so to make life easier you can usually just install the JDK and not worry about the JRE/JDK distinction.

Second step is to tell Eclipse about the new JDK. Go to Preferences... then Java > Installed JREs. Click the Search... button and Eclipse should find your newly installed JDK 1.5 and add it to the list.

Final step is to allocate that JDK 1.5 to your project. Bring up the Properties menu for your project (right-click it). Then set these values:

  • Java Compiler tab
    • Tick Enable project specific settings
    • Set Compiler Compliance level to 1.5
  • Java Build Path tab, Libraries subtab
    • Find the JRE System Library item, click Edit...
    • Set Alternate JRE to your newly installed JDK 1.5

这篇关于如何使用不同的JRE版本来编译和构建项目呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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