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

  • Home
  • SEARCH
  • 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 8982109
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:30:19+00:00 2026-06-15T20:30:19+00:00

I have a set of groovy scripts in package hierarchy. I have 1 main

  • 0

I have a set of groovy scripts in package hierarchy. I have 1 main script, from which I want to call others. For example I have these scripts (with public classes/interfaces of the same name in them):

package.MainScript
package.MyInterface;

package.utils.MyInterfaceImpl1 //implements MyInterface
package.utils.MyInterfaceImpl2 //implements MyInterface

Is there a way to call one script from the other without knowing called class name at compile time? I mean to do something like dynamic class loading like:

class MainScript {
  public static void main (String[] args) {
      MyInterface instance = Class.forName("package.utils.Util1");
  }
}
  • 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-15T20:30:20+00:00Added an answer on June 15, 2026 at 8:30 pm

    Yeah! Groovy is a dynamic language. You can create class instance dynamically.

    package.MyInterface
    class MyInterfaceImpl1 {
        def greet() {
            "Hello"
        }    
    }
    
    package.MyInterface
    class MyInterfaceImpl2 {
        def greet() {
            "Hi!"
        }   
    }
    
    def name = 'MyInterfaceImpl1' // Choose whatever you want at runtime
    def className = Class.forName("MyInterface.$name")
    def instance = className.newInstance()
    assert instance.greet() == 'Hello'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have this groovy script (in $FRAPID_HOME/bin) and I want to call it
How to pass the groovy binding to the child scripts, for example from Groovy
I have a bash script on my server which fetches master branch from github,
I'm using the cloud foundry plugin. I have set my credentials in Config.groovy. Can
I have a groovy application which is using an Oracle DB as DataSource. In
I have a Groovy/Grails web app that reads e-mails from Gmail. It gets messages
In my Groovy script I have this code: def username = System.getenv()['USER'] def password
I'm making Liquibase migration using groovy script. I have a code like def migrate()
I have a groovy DSL script like this: entity(attribute1:one, attribute2:two) so far so good.
I have developed a grails/groovy application for a legacy database which has user maintenance

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.