In Eclipse IDE, Ant build script is executed under the same JRE of the enclosing project. For example, this project is configured with JRE 7:

Eclipse project JRE

Then any Ant script created in this project will be executed under JRE 7 by default:

Ant script running under JRE7

Sometimes we need to run Ant script in another JRE which differs from the project’s JRE. To change this behavior, click Run > External Tools > External Tools Configurations… from Eclipse’s main menu:

Eclipse menu External Tools Configuration

In the External Tools Configurations dialog, select an Ant build file on the left, then JRE tab on the right:

select separate JRE for an ant build script

Now we have three options to specify a JRE for the selected Ant build file:

    • Run in the same JRE as the workspace.
    • Execution environment.
    • Separate JRE.


For example, we select jre6 in the dropdown list. If you don’t see the desired JRE, click on Installed JREs… button to add one.

Click Apply to apply the change and click Close to close the dialog. Now execute a target of the build file again, and we will see Ant is executed under the new selected JRE 6:

Ant script running under JRE6

NOTE:

We can specify different JREs for different Ant build files in the External Tools Configurations dialog. In case you don’t see any Ant build file here, that means your Ant build file has not been configured in the project. To configure, click New button and Eclipse will automatically load the default build.xml file under project’s directory. If your build file has different name, click Browse Workspace… button to locate it:

new Ant build configuration

In case you want new Ant build files always running under the same JRE as the workspace, select Window > Preferences to bring the Preferences dialog:

Ant preferences

Select Ant branch, then check the option “Always run new Ant configurations in the same JRE as the workspace”.

 

Related Tutorials:

 

Other Eclipse Tutorials:


About the Author:

is certified Java programmer (SCJP and SCWCD). He began programming with Java back in the days of Java 1.4 and has been passionate about it ever since. You can connect with him on Facebook and watch his Java videos on YouTube.



Add comment

   


Comments 

#3Andrea Cammoranesi2022-03-19 11:43
Thank you very much! You made my day!
Quote
#2Đặng Duy Tùng2021-09-24 04:09
Thanks, master, it save my time
Quote
#1nileshpasare51402020-05-03 15:21
Like to like follow to follow
Quote