How do I auto load a database jar in Groovy without using the -cp switch?

后端 未结 5 1069
既然无缘
既然无缘 2020-12-03 00:12

I want to simplify my execution of a Groovy script that makes calls to an Oracle database. How do I add the ojdbc jar to the default classpath so that I can run:

<         


        
5条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-03 00:42

    There are a few ways to do it. You can add the jar to your system's CLASSPATH variable. You can create a directory called .groovy/lib in your home directory and put the jar in there. It will be automatically added to your classpath at runtime. Or, you can do it in code:

    this.class.classLoader.rootLoader.addURL(new URL("file:///path to file"))
    

提交回复
热议问题