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 7852175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:21:31+00:00 2026-06-02T19:21:31+00:00

I know I have to be doing something just brain-dead stupid for this not

  • 0

I know I have to be doing something just brain-dead stupid for this not to work, but I’m in a situation where I want to dynamically load behavior into a running server. I chose groovy as my tool to do this. The behavior will need to reference classes on the server’s classpath, such as my model objects as well as third party libraries like Freemarker.

I threw together this silly POC to show feasibility. I can’t get the groovy script to resolve the Java classes “ThingyDoodle” and “Fooable”, in spite of the fact that I am setting the parent classpath of the GroovyClassPath to be my current.

public class GroovyTest
{
    public static void main ( String [ ] argv ) throws Throwable
    {
            // Setting parent classloader!
            // also tried plain old "GroovyTest.class.getClassLoader()" as well
        GroovyClassLoader gcl = new GroovyClassLoader ( Thread.currentThread().getContextClassLoader() ) ;
        String src =
              "class Arf implements Fooable {
                 public String foo ( ) {
                   return new ThingyDoodle().doStuff('Arf');}}" ;
        Class clazz = gcl.parseClass(src, "AppleSauce.groovy");
        Object aScript = clazz.newInstance();
        Fooable myObject = (Fooable) aScript;
        System.out.println ( myObject.foo() ) ;
    }

    public static interface Fooable { public String foo ( ) ; }

    public static class ThingyDoodle
    {
        public String doStuff ( String input )
        {
            return "Hi Worlds" ;
        }
    }
}

What the heck am I doing wrong here?

Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
AppleSauce.groovy: 1: unable to resolve class Fooable
 @ line 1, column 1.
   class Arf implements Fooable { public String foo ( ) { return new ThingyDoodle().doStuff('Arf');}}
   ^

AppleSauce.groovy: 1: unable to resolve class ThingyDoodle
 @ line 1, column 63.
   ublic String foo ( ) { return new Thingy
                                     ^
  • 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-02T19:21:32+00:00Added an answer on June 2, 2026 at 7:21 pm

    The problem in your code is that the Fooable interface and ThingyDoodle class cannot be found because they’re both internal classes and need to be qualified with the containing class name, i.e. GroovyTest. I qualified both names in the embedded script (and fixed the quotes around the script) and it ran as expected.

    import groovy.lang.GroovyClassLoader;
    
    public class GroovyTest
    {
    
        public static void main ( String [ ] argv ) throws Throwable
        {
                // Setting parent classloader!
                // also tried plain old "GroovyTest.class.getClassLoader()" as well
            GroovyClassLoader gcl = new GroovyClassLoader ( Thread.currentThread().getContextClassLoader() ) ;
            String src =
                  "class Arf implements GroovyTest.Fooable { " + 
                     "public String foo ( ) { " + 
                       "return new GroovyTest.ThingyDoodle().doStuff('Arf');}}" ;
            Class clazz = gcl.parseClass(src, "AppleSauce.groovy");
            Object aScript = clazz.newInstance();
            Fooable myObject = (Fooable) aScript;
            System.out.println ( myObject.foo() ) ;
        }       
         public static interface Fooable { public String foo ( ) ; }
    
        public static class ThingyDoodle
        {
            public String doStuff ( String input )
            {
                return "Hi Worlds" ;
            }
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know I'm doing something stupid and probably obvious, but I'm not sure what.
I have just recently been doing something in C#, i would like to know
I know I have to be doing something wrong, but again I don't fully
I know I am probably just doing something dumb wrong, but I need to
Here is the code i have and its doing something, just not what i
I know there have been some similar questions to this, but they haven't helped
I know there have been a million questions asking this, but mine is different.
I know I'm doing something wrong here, I just don't know what as I'm
I'm probably doing something stupid, but I can't spot it. I've installed Eclipse Helios
Okay, I know I have to be doing something wrong here because the performance

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.