The reason why this error occurs is that when ant is executed, the memory given to the JVM by default is not enough. You need to increase the amount of memory allowed to be used by setting startup parameters. If you are executing ANT directly through the command line, then you can directly modify the startup command. However, when executing on Eclipse, the command line settings are not easy to use.
I also tried it several times and finally got it right.
The setting method we strive for is to set parameters directly on the execution JVM of Eclipse, as follows:
1. Open Window->Preferences->Java->Installed JREs
2. Select the JDK used by default (currently)
3. Click Edit... and add appropriate parameters to Default VM Arguments, for example: -Xmx1024m