- Details
- Written by Nam Ha Minh
- Last Updated on 07 August 2019   |   Print Email
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:
Then any Ant script created in this project will be executed under JRE 7 by default:
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:
In the
External Tools Configurations dialog, select an Ant build file on the left, then
JRE tab on the right:
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:
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:
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:
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:
Nam Ha Minh is certified Java programmer (SCJP and SCWCD). He started programming with Java in the time of Java 1.4 and has been falling in love with Java since then. Make friend with him on
Facebook and watch
his Java videos you YouTube.