You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

Groovy - sharing classes and functions between files

Accepted answer


Content (required):

is it possible to share classes and methods written in one groovy file (in groovy script) with other groovy script files.

E.g. If I have a file in my calc manager rules folder as follows: GroovyFile1 containing the class and function definitions as follows:

public class Car
   String make
   String model
   double mpg
   public Car(String v_make, String v_model, double v_mpg)
      make = v_make
      model = v_model
      mpg = v_mpg
	double costPerMile()
    	return (1.51 * 4.54)/mpg


Then suppose I have a second file GroovyFile2 , is it possible to create instances of the class in this file from GroovyFile1 e.g.

Howdy, Stranger!

Log In

To view full details, sign in.


Don't have an account? Click here to get started!