如何在常规脚本中包含jar文件? [英] How do I include jars in a groovy script?
本文介绍了如何在常规脚本中包含jar文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个groovy脚本,需要一个jar文件库。我如何将它添加到类路径?我希望脚本是可执行的,所以我在脚本的顶部使用#!/ 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())
这篇关于如何在常规脚本中包含jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文