简体   繁体   English

如何在没有JAR的其他包中使用Groovy类?

[英]How can I use Groovy classes in other packages without JAR?

I'm pretty new to Groovy (coming from Java), so this may be a stupid question :-) 我是Groovy的新手(来自Java),所以这可能是一个愚蠢的问题:-)

Nonetheless: I'd like to structure a couple of Groovy scripts using packages. 尽管如此:我想使用包构建一些Groovy脚本。 And I'd like to import some general Groovy classes from some other package. 我想从其他一些包中导入一些常规的Groovy类。

How can I make sure that my Groovy scripts finds the other classes in the other packages? 如何确保我的Groovy脚本在其他包中找到其他类? The only classpath related files I can remember are JARs. 我能记住的唯一类路径相关文件是JAR。

If you from java: 如果你来自java:

Groovy loads classes as java and also includes non-compiled with extension .groovy . Groovy将类加载为java,还包括非编译扩展名.groovy

So, you have to place your classes relative to classpath according to their package name. 因此,您必须根据包名称将类相对于类路径放置。

The command line should be something like this: 命令行应该是这样的:

groovy -cp "path_to_classes_root" "path_and_name_of_main_groovy_script.groovy"

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

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