How can I tell Eclipse to compile and build a project with a different version of the JRE than usual?

I'm not sure if this question is answered in full or if my title is quite descriptive given my situation, but I was asked to convert the project from Ant to Maven. This part is not so bad, but I was told that this application was developed specifically for JRE version 1.5, and not JRE 6, all that I did using. Now I'm incredibly new to Eclipse and Java, so I was a bit confused when I was asked to tell Eclipse or Maven to create this particular project using JRE 1.5 instead. I believe that it is installed, and I tried to follow the steps described here: ( Eclipse: create and match different versions of the JRE ), but I get hooked.

I was able to modify the launch configuration to use the alternative jre jre1.5.0_11 JRE. When I 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 use JDK 1.5 to use JRE 1.5 since I am working with JDK 1.6 right now. Now, is there a way to install JDK 1.5 so this project can use it? My JAVA_HOME variable currently points to JDK 1.6, and I would like it to stay that way ... Is there a way to use them and just tell the project (either Eclipse or Maven ... however it works) to use the specific version JDK?

+8
java eclipse
source share
2 answers

Yes it is possible. You can install as many different versions of Java - JRE and JDK - as you like, and tell Eclipse which one to use for each project.

The first step is to install JDK 1.5 on your computer (JDK is not suitable for the "Java [SE] Development Kit", look for it 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 difference in JRE / JDK.

The second step is to tell Eclipse about the new JDK. Go to Settings ... then Java> Installed JREs. Click the "Search ..." button, and Eclipse should find your recently installed JDK 1.5 and add it to the list.

The final step is to allocate this JDK 1.5 to your project. Open the Properties menu for your project (right-click on it). Then set the following values:

  • Java Compiler Tab
    • Tick ​​Enable special project settings
    • Set compiler compatibility level to 1.5
  • Java Path tab, Libraries tab
    • Find the JRE system library item, click "Edit" ...
    • Define an alternative JRE to your newly installed JDK 1.5
+16
source share

It looks like you are using JRE 1.5, not JDK 1.5

Make sure you download JDK 1.5 and your problem should go away. You can set the JDK by default in the settings, find "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

+2
source share

All Articles