How Can I Tell Eclipse to Compile and Build a Project with a Different JRE Version than it Normally Does?

拜拜、爱过 提交于 2019-12-04 03:03:21

问题


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?


回答1:


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



回答2:


It looks like you are using JRE 1.5 rather than JDK 1.5

Make sure you download the JDK 1.5 and your issue should go away. You can set the default JDK in the preferences, search for 'jre'.

Projects can also define their specific jre

Get JDK 1.5 from Here http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html



来源:https://stackoverflow.com/questions/9302687/how-can-i-tell-eclipse-to-compile-and-build-a-project-with-a-different-jre-versi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!