如何在 groovy 脚本中包含 jars? [英] How do I include jars in a groovy script?
本文介绍了如何在 groovy 脚本中包含 jars?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个需要 jar 中的库的 groovy 脚本.我如何将它添加到类路径?我希望脚本是可执行的,所以我在脚本顶部使用 #!/usr/bin/env groovy
.
I have a groovy script that needs a library in a jar. How do I add that to the classpath? I want the script to be executable so I'm using #!/usr/bin/env groovy
at the top of my script.
推荐答案
如果你真的需要,你也可以在运行时加载 JAR:
If you really have to you can also load a JAR at runtime with:
this.getClass().classLoader.rootLoader.addURL(new File("file.jar").toURL())
这篇关于如何在 groovy 脚本中包含 jars?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文