DEV Community

Darshit Patel
Darshit Patel

Posted on • Originally published at darshit.dev

1

How to change Java Version/JAVA_HOME for Ant?

Want to change Java Version/JAVA_HOME for Ant builds?

  1. Open ~/.antrc file by running vim ~/.antrc
  2. Add JAVACMD=<NEW_JAVA_HOME>/bin/java and save

The Ant wrapper script for Unix will source (read and evaluate) the file ~/.antrc before it does anything.
On Windows, the Ant wrapper batch-file invokes %HOME%\antrc_pre.bat at the start and %HOME%\antrc_post.bat at the end.
You can use these files, for example, to set/unset environment variables that should only be visible during the execution of Ant.

The wrapper scripts use the following environment variables (if set):

  • JAVACMD—full path of the Java executable. Use this to invoke a different JVM than JAVA_HOME/bin/java(.exe).
  • ANT_OPTS—command-line arguments that should be passed to the JVM. For example, you can define system properties or set the maximum Java heap size here.
  • ANT_ARGS—Ant command-line arguments. For example, set ANT_ARGS to point to a different logger, include a listener, and to include the -find flag. Note: If you include -find in ANT_ARGS, you should include the name of the build file to find, even if the file is called build.xml.

Source: https://ant.apache.org/manual/running.html

Check out my website at: https://darshit.dev

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs