Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7927169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:10:33+00:00 2026-06-03T19:10:33+00:00

Invoking a groovy script using CLASSPATH prefix as follows works fine: CLASSPATH=/path/to/classes groovy -e

  • 0

Invoking a groovy script using CLASSPATH prefix as follows works fine:

CLASSPATH=/path/to/classes groovy -e "(new stuff.XMLUtils()).printIt('test string')"

but changing it to use the classpath arg doesn’t:

groovy -classpath /path/to/classes -e "(new stuff.XMLUtils()).printIt('test string')"

and gives the error:

script_from_command_line: 1: unable to resolve class stuff.XMLUtils

Can anyone explain why this is? (The stuff.XMLUtils is just some groovy script i’ve compiled into /path/to/classes
)

I’ve done some investigation, and using the following groovy script to dump the classloader

def printClassPath(classLoader) {
  println "$classLoader"
  classLoader.getURLs().each {url->
     println "- ${url.toString()}"
  }
  if (classLoader.parent) {
     printClassPath(classLoader.parent)
  }
}
printClassPath this.class.classLoader

With the -classpath arg, i see no entry in the classloader for the passed in classpath arg, (in fact, the only directory is the current working dir), e.g.:

groovy.lang.GroovyClassLoader$InnerLoader@4911b910
groovy.lang.GroovyClassLoader@18203c31
sun.misc.Launcher$AppClassLoader@35a16869
- file:/usr/share/java/ant.jar
- ... (removed for brevity)
- file:/home/admin/groovy/
sun.misc.Launcher$ExtClassLoader@77cde100
- file:/usr/java/jdk1.6.0_23/jre/lib/ext/sunjce_provider.jar
- ...

Using the CLASSPATH=... version shows that the PWD entry above is replaced by the value i’ve set in the variable.

And if I add debug to the groovy shell executable, the difference in the java call is that the -classpath arg version adds no entry to java’s classpath entry (which is ultimately why it’s giving a class not found error), but the CLASSPATH=... version does add the path.

Is this a bug in groovy?

EDIT: simple failing example

- - - - xu.groovy
package stuff
def printIt(string) { println string }
- - - -

groovyc -d classes xu.groovy
groovy -cp classes -e "(new stuff.xu()).printIt('test')"  # fails
CLASSPATH=classes groovy -e "(new stuff.xu()).printIt('test')"  # works

If I remove the package and references to stuff the failing example will work fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T19:10:34+00:00Added an answer on June 3, 2026 at 7:10 pm

    Answering this myself because I found a solution to the problem.

    I was using the default groovy packages from yum in fedora, however found many issues (errors starting groovysh etc, unable to find jline package etc), and have wholly moved over to using downloaded versions from codehaus.org, and manually specifying GROOVY_HOME and editing path to invoke the downloaded one instead.

    Now all my examples work as expected.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am invoking a shell script using Kernel.system from my Rails controller. The shell
I'm loading a Groovy script/class from a remote server, creating a new instance, and
I am invoking an exe file (which is essentially a cgi script) with using
I am invoking a camera using an intent and clicking a picture. Presently I
What I want to do is invoke maven from a groovy script. The groovy
I am invoking a mail intent in ImageButton mail=(ImageButton)findViewById(R.id.mailgps); mail.setOnClickListener(new View.OnClickListener() { @Override public
I found a C# example here of invoking a PowerShell script asynchronously from a
Do you know something about possibilites of invoking Scala from R and using R
I am invoking a javascript function for drilling down the chart. I tried using
This is similar to Invoking a method using reflection on a singleton object but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.