{"id":229,"date":"2010-04-14T07:00:20","date_gmt":"2010-04-14T07:00:20","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2010\/04\/14\/usage-of-ant_opts-in-ant-script-ant_opts-capabilities\/"},"modified":"2017-12-27T06:50:48","modified_gmt":"2017-12-27T06:50:48","slug":"usage-of-ant_opts-in-ant-script-ant_opts-capabilities","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/usage-of-ant_opts-in-ant-script-ant_opts-capabilities\/","title":{"rendered":"Usage of ANT_OPTS in Ant Script | ANT_OPTS capabilities"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-4239\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2010\/04\/ant_opts-in-ant-script.png\" alt=\"ant_opts-in-ant-script\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/04\/ant_opts-in-ant-script.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2010\/04\/ant_opts-in-ant-script-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><b>Usage of ANT_OPTS in Ant Script | ANT_OPTS capabilities<\/b><\/p>\n<p>Ant has three environment variables that you can use to set its default behavior.<br \/>\n\u2022 ANT_ARGS Set this variable to include those options you use frequently.<br \/>\n\u2022 ANT_OPTS is a list of arguments that you want to pass to the JVM that will run Ant.<br \/>\n\u2022 JAVACMD is the absolute path to the Java executable you want Ant to use. you may specify a value for the JAVACMD environment variable. This defaults to %JAVA_HOME%\\bin\\java, typically invoking the JVM provided in Sun&#8217;s Java Development Kit. Ant provides JAVACMD for those who wish to specify an alternate JVM. full path of the Java executable. Use this to invoke a different JVM than JAVA_HOME\/bin\/java(.exe).<\/p>\n<p>These are useful environment variables that the Ant wrapper scripts use when<br \/>\ninvoking Ant: ANT_OPTS and ANT_ARGS. Neither of these is typically set by users,<br \/>\nbut each can provide value for certain situations.<\/p>\n<p>The ANT_OPTS environment variable provides options to the JVM executing Ant,<br \/>\nsuch as system properties and memory configuration. ANT_OPTS &#8211; 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.<\/p>\n<p><b>For authenticated proxy: <\/b><br \/>\nSet your ANT_OPTS environment variable to configure your proxy if you have one. For instance:<br \/>\nset ANT_OPTS=-Dhttp.proxyHost=myproxy -Dhttp.proxyPort=3128<\/p>\n<p>You can set these properties by either modifying Ant&#8217;s startup script, or by<br \/>\nusing the ANT_OPTS environment variable. The following example shows the Windows commands to specify these properties using ANT_OPTS, and then to invoke Ant:<br \/>\nset ANT_OPTS=-DproxySet=true -DproxyHost=localhost -DproxyPort=80<br \/>\nant mytarget<br \/>\nThe same trick works on Unix, although the syntax is slightly different depending on which<br \/>\nshell you use:<br \/>\n$ export ANT_OPTS=&#8221;-DproxySet=true -DproxyHost=localhost -DproxyPort=80&#8243;<br \/>\n$ ant mytarget<\/p>\n<p>set ANT_OPTS=-Dhttp.proxyHost=myproxyhost -Dhttp.proxyPort=8080 -Dhttp.proxyUserName=myproxyusername -Dhttp.proxyPassword=myproxypassword -Dhttps.proxyHost=myproxyhost -Dhttps.proxyPort=8080<\/p>\n<p>&nbsp;<\/p>\n<p><b>Use <\/b><b>ANT_OPTS <\/b><b>to control Ant\u2019s virtual machine settings.<\/b><br \/>\nSome tasks may require more memory, which you can set in the ANT_OPTS environment variable, using the appropriate mechanism for your platform:<br \/>\nset ANT_OPTS=-Xmx500M<br \/>\nexport ANT_OPTS=-Xmx500M<\/p>\n<p>Setting the maximum heap size is another common use of ANT_OPTS. Here is how we set the maximum size to 128 MB when using Sun&#8217;s JDK:<br \/>\nset ANT_OPTS=-Xmx128m<\/p>\n<p>One environment variable you may wish to set is ANT_OPTS. The value of this variable is passed as a JVM argument. Specifying system properties is a common use. In this simple<br \/>\n<b>example, we pass the <\/b><b>log.dir <\/b><b>system property to the JVM running Ant:<\/b><br \/>\n$ set ANT_OPTS=-Dlog.dir=C:\\logs<br \/>\n$ ant run<br \/>\nNow this property is available within the buildfile, for instance:<br \/>\n&lt;echo&gt;Log directory is set to: ${log.dir}&lt;\/echo&gt;<br \/>\nIf the buildfile runs a Java application, the property may be retrieved from within it as<br \/>\nfollows:<br \/>\nString logDir = System.getProperty(&#8220;log.dir&#8221;);<\/p>\n<p>&nbsp;<\/p>\n<p><b>Troubleshoot: Illegal Java options in the ANT_OPTS variable<\/b><br \/>\nThe environment variable ANT_OPTS provides a means to pass options into Ant,<br \/>\nsuch as a permanent definition of some properties, or the memory parameters for<br \/>\nJava. The variable must contain only options the local JVM recognizes. Any invalid<br \/>\nparameter will generate an error message such as the following (where ANT_OPTS was<br \/>\nset to \u20133):<br \/>\nUnrecognized option: -3<br \/>\nCould not create the Java virtual machine.<\/p>\n<p>If the variable contains a string that is mistaken for the name of the Java class to run<br \/>\nas the main class, then a different error appears:<\/p>\n<p>Exception in thread &#8220;main&#8221; java.lang.NoClassDefFoundError: error-string<br \/>\nTest: Examine ANT_OPTS and verify that the variable is unset or contains valid<br \/>\nJVM options.<br \/>\nFix: Correct or clear the variable.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Usage of ANT_OPTS in Ant Script | ANT_OPTS capabilities Ant has three environment variables that you can use to set its default behavior. \u2022 ANT_ARGS Set this variable to include those options you use frequently. \u2022 ANT_OPTS is a list of arguments that you want to pass to the JVM that will run Ant. \u2022&#8230;<\/p>\n","protected":false},"author":1,"featured_media":4239,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","_joinchat":[],"footnotes":""},"categories":[12],"tags":[209,3795,3799,3801,3797,3798,3045,683,3796,3800,1122,3802,1806,938,213,3794],"class_list":["post-229","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apache-ant","tag-ant","tag-ant-opts","tag-ant-opts-capabilities","tag-ant-opts-in-ant-script","tag-ant-opts-usage","tag-ant-opts-usage-in-ant-script","tag-ant-script","tag-apache-ant","tag-capabilities","tag-capabilities-of-ant-opts","tag-guide","tag-how-to-use-ant-opts-in-ant-script","tag-instruction","tag-reference","tag-tutorial","tag-usage"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=229"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/229\/revisions"}],"predecessor-version":[{"id":4241,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/229\/revisions\/4241"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/4239"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=229"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=229"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}