Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Starting a groovy script with <code>#!/usr/bin/env groovy</code> has a very important limitation - <strong>No additional arguments can be added.</strong> No classpath can be configured, no running groovy with defines or in debug. This is not a <a href="http://jira.codehaus.org/browse/GMOD-226" rel="noreferrer" title="groovy issue">groovy</a> issue, but a limitation in how the shebang (<code>#!</code>) works - all additional arguments are treated as single argument so <code>#!/usr/bin/env groovy -d</code> is telling <code>/usr/bin/env</code> to run the command <code>groovy -d</code> rathen then <code>groovy</code> with an argument of <code>d</code>.</p> <p>There is a workaround for the issue, which involves bootstrapping groovy with bash <strong>in the groovy script.</strong> </p> <pre><code>#!/bin/bash //usr/bin/env groovy -cp extra.jar:spring.jar:etc.jar -d -Dlog4j.configuration=file:/etc/myapp/log4j.xml "$0" $@; exit $? import org.springframework.class.from.jar //other groovy code println 'Hello' </code></pre> <p>All the magic happens in the first two lines. The first line tells us that this is a <code>bash</code> script. <code>bash</code> starts running and sees the first line. In <code>bash</code> <code>#</code> is for comments and <code>//</code> is collapsed to <code>/</code> which is the root directory. So <code>bash</code> will run <code>/usr/bin/env groovy -cp extra.jar:spring.jar:etc.jar -d -Dlog4j.configuration=file:/etc/myapp/log4j.xml "$0" $@</code> which starts groovy with all our desired arguments. The <code>"$0"</code> is the path to our script, and <code>$@</code> are the arguments. Now groovy runs and it ignores the first two lines and sees our groovy script and then exits back to <code>bash</code>. <code>bash</code> then exits (<code>exit $?1</code>) with status code from groovy.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload