2011-06-09 106 views
3

我遇到了jar文件和常规问题。对于一些特定的示例,我试图连接到postgresql数据库,并且在使用 sql = Sql.newInstance("jdbc:postgresql://localhost", "user", "pass", "org.postgresql.Driver") 时,我得到了org.postgresql.Driver的ClassNotFound异常。我的$ {user.home} /。groovy/lib中有postgresql jar,并且从groovy-starter.conf中加载的行没有被注释掉。我也遇到了与dbunit.jar文件类似的问题。Groovy不读取.groovy中的jar文件/ lib

如果我尝试手动添加使用Groovy -cp classpath中我得到的是说 Caught: java.io.UnsupportedEncodingException: p

任何想法的错误?

+0

你能后的'java.io.UnsupportedEncodingException'的完整堆栈跟踪? – 2011-06-11 16:44:18

回答

1

按照CLI帮助 - http://groovy.codehaus.org/Groovy+CLI

$groovy -help 
usage: groovy 
-a,--autosplit <splitPattern> automatically split current line 
           (defaults to '\s') 
-c,--encoding <charset> specify the encoding of the files 
-e <script>    specify a command line script 
-h,--help     usage information 
-i <extension>   modify files in place 
-l <port>     listen on a port and process inbound lines 
-n      process files line by line 
-p      process files line by line and print result 
-v,--version    display the Groovy and JVM versions 

groovy -cp会告诉groovy加载字符集p不存在。

您试图使用${user.home}/.groovy/lib应该已经工作,假设您使用了正确的路径${user.home}。如果您在操作系统上添加信息,我们可能会看到您是否正确。

作为WA - 只需将环境变量CLASSPATH导出到罐子所在的任何位置。

的Windows:set CLASSPATH=c:\temp\postgresql.jar;c:\temp\dbunit.jar ... 的Unix/Linux(KSH):export CLASSPATH=${HOME}/temp/postgresql.jar:${TEMP}/temp/dbunit.jar ...