How to change JRE for Ant in Eclipse
- 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:
- How to create Ant build file for existing Java project in Eclipse
- Add custom Ant build script to Eclipse project
Other Eclipse Tutorials:
- How to use Eclipse IDE for Java EE Developers
- How to create, build and run a Java Hello World program with Eclipse
- How to generate Javadoc in Eclipse
- How to create WAR file for Java web application in Eclipse
- How to create JAR file in Eclipse
- How to pass arguments when running a Java program in Eclipse
- How to create Java web project with Maven in Eclipse
- 25 Eclipse Shortcut Keys for Code Editing
- How to Add Copyright License Header for Java Source Files in Eclipse
Comments