Problem defining classpath in shebang on linux

View: New views
4 Messages — Rating Filter:   Alert me  

Problem defining classpath in shebang on linux

by bgilbert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I'm trying to run run a groovy script using a shebang in linux. I've
defined the classpath for the script in the shebang, however I'm
getting a weird error when trying to execute the script:

------
Caught: BUG! exception in phase 'parsing' in source unit
'/home/bgilbert/scripts/test.groovy' p /home/bgilbert/lib
------

The shebang that I am using is:

-----
#!/usr/bin/groovy -cp /home/bgilbert/lib
-----

When I try to run the command at the command line: '/usr/bin/groovy
-cp /home/bgilbert/lib test.groovy', I have no problems at all. Anyone
know if there is an error on my part or if this is  bug in groovy?

Thanks in advance!
Bryan

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Problem defining classpath in shebang on linux

by Roshan Dawrani-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you want to manipulate the classpath at runtime for a specific script, you can use the following concept (change it for jars/class folders that you want to use):

============================================================
this.getClass().classLoader.rootLoader.addURL(new File("file.jar").toURL())
============================================================

-- Roshan


On Tue, Oct 27, 2009 at 12:24 AM, William Gilbert <gilbertw1@...> wrote:
Hi,

I'm trying to run run a groovy script using a shebang in linux. I've
defined the classpath for the script in the shebang, however I'm
getting a weird error when trying to execute the script:

------
Caught: BUG! exception in phase 'parsing' in source unit
'/home/bgilbert/scripts/test.groovy' p /home/bgilbert/lib
------

The shebang that I am using is:

-----
#!/usr/bin/groovy -cp /home/bgilbert/lib
-----

When I try to run the command at the command line: '/usr/bin/groovy
-cp /home/bgilbert/lib test.groovy', I have no problems at all. Anyone
know if there is an error on my part or if this is  bug in groovy?

Thanks in advance!
Bryan

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email




RE: Problem defining classpath in shebang on linux

by Antti Karanta :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message



> -----Original Message-----
> From: William Gilbert [mailto:gilbertw1@...]
>
> know if there is an error on my part or if this is  bug in groovy?

  Could be this one: http://jira.codehaus.org/browse/GROOVY-3131

  To quote from
http://osdir.com/ml/gnu.sh-utils.bugs/2002-04/msg00020.html 
"The #! syntax is generally called the Berkeley #! hack. It was a
wonderful improvement over not having it at all. But is still
considered a hack because it has many limitations. One is that only
one argument is allowed."

  You're hitting the "only one argument" limit. What happens is that
when you call
#!/usr/bin/groovy -cp /home/bgilbert/lib
  the invoked program (groovy) does not get two parameters (-cp and
/home/bgilbert/lib) but one ("-cp /home/bgilbert/lib") which does not
have the expected behavior (as command line parsing assumes the command
line has been split into tokens).



    ::Antti::



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email



Re: Problem defining classpath in shebang on linux

by bgilbert :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That makes a lot of sense! I think I'll use the class loader method to
meet my needs, although I think the shebang would have been a nicer
solution. Thanks for your help!

On Tue, Oct 27, 2009 at 2:08 AM, Antti Karanta <antti.karanta@...> wrote:

>
>
>> -----Original Message-----
>> From: William Gilbert [mailto:gilbertw1@...]
>>
>> know if there is an error on my part or if this is  bug in groovy?
>
>  Could be this one: http://jira.codehaus.org/browse/GROOVY-3131
>
>  To quote from
> http://osdir.com/ml/gnu.sh-utils.bugs/2002-04/msg00020.html
> "The #! syntax is generally called the Berkeley #! hack. It was a
> wonderful improvement over not having it at all. But is still
> considered a hack because it has many limitations. One is that only
> one argument is allowed."
>
>  You're hitting the "only one argument" limit. What happens is that
> when you call
> #!/usr/bin/groovy -cp /home/bgilbert/lib
>  the invoked program (groovy) does not get two parameters (-cp and
> /home/bgilbert/lib) but one ("-cp /home/bgilbert/lib") which does not
> have the expected behavior (as command line parsing assumes the command
> line has been split into tokens).
>
>
>
>    ::Antti::
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email