java 在ant脚本中设置环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3664000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Setting up environment variable in ant script
提问by Vijay Shanker Dubey
I am using ant for building my projects, This project needs more memory then default JVM size, So I have added following line of code in the build.xml
file.
我正在使用 ant 来构建我的项目,这个项目需要比默认 JVM 大小更多的内存,所以我在build.xml
文件中添加了以下代码行。
<!-- setting up this value as project need this much memory to compile.-->
<property environment="env" />
<property name="env.ANT_OPTS" value="-Xms1024m -Xmx204888m" />
But above line of code does not seems to have any effect as I am still getting the heap size problem. So I have decided to use a batch
script for launching the build. The line of code in the given batch file is below
但是上面的代码行似乎没有任何影响,因为我仍然遇到堆大小问题。所以我决定使用batch
脚本来启动构建。给定批处理文件中的代码行如下
set ANT_OPTS=-Xms512m -Xmx778m
ant -f agora-build.xml
This batch script successfully launch and executes the ant script. But this is not what I am looking for. Is there a way exists, so that I can setup this argument in the ant script itself?
此批处理脚本成功启动并执行 ant 脚本。但这不是我要找的。有没有办法存在,以便我可以在 ant 脚本本身中设置这个参数?
What should i do?
我该怎么办?
Thanks, VSD
谢谢,VSD
采纳答案by Sean
If you are running the Ant script in Eclipse
如果您在 Eclipse 中运行 Ant 脚本
Right Click -> Run As -> External Tools Configuration
右键单击 -> 运行方式 -> 外部工具配置
(Add the build if it isn't there already)
(如果它不存在,则添加构建)
Go to the JRE tab and add the Xms and Xmx arguments to the VM arguments section.
转到 JRE 选项卡并将 Xms 和 Xmx 参数添加到 VM 参数部分。
*edit: "-Xmx204888m" I hope 2 of those 8's are typo's
*编辑:“-Xmx204888m”我希望这8个中有2个是错字
回答by mlschechter
If you set the option in the build script, the JVM is already up and configured; the only way to set JVM-level options from within a build file is to have Ant spawn another JVM (using the java
taskas a launcher, or the ant
task).
如果您在构建脚本中设置了该选项,则 JVM 已经启动并配置好了;在构建文件中设置 JVM 级别选项的唯一方法是让 Ant 生成另一个 JVM(使用java
任务作为启动器或ant
任务)。
You can also set ANT_OPTS
as an environment variable; that will affect all Ant builds you run and pass the provided options to the JVM that Ant runs in.
也可以设置ANT_OPTS
为环境变量;这将影响您运行的所有 Ant 构建并将提供的选项传递给 Ant 运行的 JVM。