创建自己的 groovy 库 [英] Creating own groovy library
问题描述
有没有人知道为 groovy 创建自己的库的最佳方法是什么.
Do anyone have an idea whats the best way of creating an own library for groovy.
我有几种方法,我只是不想将它们复制并粘贴到我所有的 groovy 脚本中.
I have several methods which i just dont want copy and paste into all my groovy scripts.
完美的解决方案是通过
The perfect solution would be to do it by an
import myownmethods
如何创建库 myownmethods.jar?
How to create the library myownmethods.jar?
感谢您的任何回答和解决方案
Thanks for any answer and solution
干杯
推荐答案
最简单的方法就是用groovyc
编译你的groovy文件,然后用jar
打包成jar文件代码>.例如:
The simplest method is to compile your groovy files with groovyc
and then package them into a jar file with jar
. For example:
groovyc -d classes myclasses.groovy
jar cvf myclasses.jar -C classes .
我也会考虑看 gradle.首先,您可以使用 build.gradle
只包含:
I'd also consider looking at gradle. To get started, you can use a build.gradle
containing just:
apply plugin: 'groovy'
然后将您的源文件放在名为 src/main/groovy
的子目录中并运行 gradle jar
.它会将您的源文件构建到 build/libs
中的 jar 文件中.
Then put your source files in a subdirectory called src/main/groovy
and run gradle jar
. It will build your source files into a jar file in build/libs
.
这篇关于创建自己的 groovy 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!