简体   繁体   English

如何将groovy脚本中定义的类导入另一个groovy

[英]How to import a class defined in groovy script into another groovy

I have a created a groovy script which contains a class with some attributes and methods. 我创建了一个Groovy脚本,其中包含带有一些属性和方法的类。 I have also created another groovy script in which a class is calling methods from the first groovy script but I am getting the error: 我还创建了另一个groovy脚本,其中一个类从第一个groovy脚本调用方法,但出现错误:

Unable to resolve class 无法解决课程

Also, both the scripts are under same package. 另外,两个脚本都在同一程序包下。 My question is how to access a class (attributes/methods) defined in a different script? 我的问题是如何访问不同脚本中定义的类(属性/方法)?

Thanks. 谢谢。

Add @PackageScope annotation above the method or attribute you wish to access in another class from the same package. 在要从同一包的另一个类中访问的方法或属性上方,添加@PackageScope批注。 You can also add it to the class itself. 您也可以将其添加到类本身。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM