当尝试从命令行运行我的程序(在intellij中工作)时,我收到以下错误:
Exception in thread "main" groovy.lang.MissingPropertyException: No such property: Sql for class: com...GetIpUtilization
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at com.ibbs.unity.device.GetIpUtilization.run(GetIpUtilization.groovy:48)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1085)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:909)
at org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:901)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:884)
at org.codehaus.groovy.runtime.InvokerHelper.runScript(InvokerHelper.java:406)
at org.codehaus.groovy.runtime.InvokerHelper$runScript.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at com...GetIpUtilization.main(GetIpUtilization.groovy)
这就是错误所在的地方
xbDbConn = Sql.newInstance(
"jdbc:mysql://"+DATABASE_IP+":"+DATABASE_PORT+"/"+DATABASE_NAME+"?autoReconnect=true",
DATABASE_USER,
DATABASE_PASSWORD,
"com.mysql.jdbc.Driver"
)
我正在导入groovy sql库:
import groovy.sql.Sql
我试过
import groovy.sql.*
没有运气。在这一点上,我完全没有想法。更令人沮丧的是它在intellij中工作,而不是命令行。
UDPATE
# groovy --version
Groovy Version: 2.2.2 JVM: 1.7.0_51 Vendor: Oracle Corporation OS: Linux
# jdk1.7.0_51/bin/java -jar CnrIpUtilHistory.jar
import com.cisco.cnr.sdk.client.*
import groovy.sql.*
import java.sql.SQLException
import com.cisco.cnr.sdk.*
import java.lang.*
import org.apache.commons.net.util.SubnetUtils
scriptDir = new File(getClass().protectionDomain.codeSource.location.path).parent
config = new ConfigSlurper().parse(new File("${scriptDir}/ConfigIpUtilization.groovy").toURL())
DATABASE_IP = config.mysql.ip
DATABASE_PORT = config.mysql.port
DATABASE_NAME = config.mysql.name
DATABASE_USER = config.mysql.user
DATABASE_PASSWORD = config.mysql.password
SCOPE_DATABASE_IP = config.scope.ip
SCOPE_DATABASE_PORT = config.scope.port
SCOPE_DATABASE_NAME = config.scope.name
SCOPE_DATABASE_USER = config.scope.user
SCOPE_DATABASE_PASSWORD = config.scope.password
xbDbConn = Sql.newInstance(
"jdbc:mysql://"+DATABASE_IP+":"+DATABASE_PORT+"/"+DATABASE_NAME+"?autoReconnect=true",
DATABASE_USER,
DATABASE_PASSWORD,
"com.mysql.jdbc.Driver"
)
答案 0 :(得分:3)
问题出在gradle.build文件的依赖项中。
更改了gradle.build中的以下行:
dependencies {
groovy 'org.codehaus.groovy:groovy:2.2.2'
...
为:
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.2.2'
...
这解决了这个问题。