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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:52:04+00:00 2026-05-28T22:52:04+00:00

File1.groovy def method() { println test } File2.groovy method() I want to load/include the

  • 0

File1.groovy

def method() {
   println "test"
}

File2.groovy

method()

I want to load/include the functions/methods from File1.groovy during runtime, equals to rubys/rake’s load. They are in two different directories.

  • 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-05-28T22:52:04+00:00Added an answer on May 28, 2026 at 10:52 pm

    If you don’t mind the code in file2 being in a with block, you can do:

    new GroovyShell().parse( new File( 'file1.groovy' ) ).with {
      method()
    }
    

    Another possible method would be to change file1.groovy to:

    class File1 {
      def method() {
        println "test"
      }
    }
    

    And then in file2.groovy you can use mixin to add the methods from file1

    def script = new GroovyScriptEngine( '.' ).with {
      loadScriptByName( 'file1.groovy' )
    } 
    this.metaClass.mixin script
    
    method()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In file1.php , I execute file2.php with <form action=file2.php method=POST> Within file2, I want
In Groovy Console I have this: import groovy.util.* import org.codehaus.groovy.runtime.* def gse = new
file1.txt aaaa bbbb cccc dddd eeee file2.txt DDDD cccc aaaa result bbbb eeee If
file1.txt hello tom well file2.txt world jerry done How to merge file1.txt with file2.txt;
Suppose file1 looks like this: bye bye hello thank you And file2 looks like
See code: var file1 = 50.xsl; var file2 = 30.doc; getFileExtension(file1); //returns xsl getFileExtension(file2);
I have File1 A,B,C and File2 D,E,F I am trying to have AD, AE,
For example: I want: if file1 exists: CLEAN_SRC = *.h file3 else CLEAN_SRC =
I'm trying to extract a closure from a groovy script. I define the closure
I want to execute a build.xml (Ant buildfile) from using GMaven (Maven Plugin for

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.