如何在不使用 -cp 开关的情况下在 Groovy 中自动加载数据库 jar? [英] How do I auto load a database jar in Groovy without using the -cp switch?

查看:20
本文介绍了如何在不使用 -cp 开关的情况下在 Groovy 中自动加载数据库 jar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想简化调用 Oracle 数据库的 Groovy 脚本的执行.如何将 ojdbc jar 添加到默认类路径以便我可以运行:

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:

groovy RunScript.groovy

代替:

groovy -cp ojdbc5.jar RunScript.groovy

推荐答案

总结自 Groovy Recipes,作者 Scott Davis,在 ./groovy/lib 目录中自动包含 JAR:

Summarized from Groovy Recipes, by Scott Davis, Automatically Including JARs in the ./groovy/lib Directory:

  1. 在您的登录目录中创建 .groovy/lib
  2. 在 ${GROOVY_HOME}/conf/groovy-starter.conf 中取消注释以下行

  1. Create .groovy/lib in your login directory
  2. Uncomment the following line in ${GROOVY_HOME}/conf/groovy-starter.conf

load !{user.home}/.groovy/lib/*.jar

复制你想要包含的 jars 到 .groovy/lib

Copy the jars you want included to .groovy/lib

似乎对于 Groovy 1.5 或更高版本,默认情况下您会获得此功能(无需编辑 conf),只需将 jar 放在/lib 目录中即可.

It appears that for Groovy 1.5 or later you get this by default (no need to edit the conf), just drop the jars in the /lib dir.

这篇关于如何在不使用 -cp 开关的情况下在 Groovy 中自动加载数据库 jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆