这让我觉得很荒谬,但是我似乎无法将多个jar文件添加到groovyConsole和groovysh的类路径中。如何将多个jar文件添加到类路径?这是我尝试过的:
groovyConsole -cp~ / lib / compile / jar / mysql-connector-java-5.1.32.jar:〜/ lib / compile / jar / ojdbc6-11.2.0.3.jar
但是,当我在控制台中执行此代码时,我得到以下内容:
file:/Users/charlie/lib/compile/jar/mysql-connector-java-5.1.32.jar
file:/Users/charlie/projects/fuseanalytics/./
file:/Users/charlie/.gvm/groovy/current/lib/ant-1.9.3.jar
file:/Users/charlie/.gvm/groovy/current/lib/ant-antlr-1.9.3.jar
file:/Users/charlie/.gvm/groovy/current/lib/ant-junit-1.9.3.jar
file:/Users/charlie/.gvm/groovy/current/lib/ant-launcher-1.9.3.jar
file:/Users/charlie/.gvm/groovy/current/lib/bsf-2.4.0.jar
file:/Users/charlie/.gvm/groovy/current/lib/commons-cli-1.2.jar
file:/Users/charlie/.gvm/groovy/current/lib/commons-logging-1.1.1.jar
file:/Users/charlie/.gvm/groovy/current/lib/gpars-1.2.1.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-ant-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-bsf-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-console-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-docgenerator-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-groovydoc-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-groovysh-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-jmx-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-json-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-jsr223-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-nio-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-servlet-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-sql-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-swing-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-templates-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-test-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-testng-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/groovy-xml-2.3.6.jar
file:/Users/charlie/.gvm/groovy/current/lib/hamcrest-core-1.3.jar
file:/Users/charlie/.gvm/groovy/current/lib/ivy-2.3.0.jar
file:/Users/charlie/.gvm/groovy/current/lib/jansi-1.11.jar
file:/Users/charlie/.gvm/groovy/current/lib/jcommander-1.35.jar
file:/Users/charlie/.gvm/groovy/current/lib/jline-2.11.jar
file:/Users/charlie/.gvm/groovy/current/lib/jsp-api-2.0.jar
file:/Users/charlie/.gvm/groovy/current/lib/jsr166y-1.7.0.jar
file:/Users/charlie/.gvm/groovy/current/lib/junit-4.11.jar
file:/Users/charlie/.gvm/groovy/current/lib/multiverse-core-0.7.0.jar
file:/Users/charlie/.gvm/groovy/current/lib/qdox-1.12.1.jar
file:/Users/charlie/.gvm/groovy/current/lib/servlet-api-2.4.jar
file:/Users/charlie/.gvm/groovy/current/lib/testng-6.8.8.jar
file:/Users/charlie/.gvm/groovy/current/lib/xmlpull-1.1.3.1.jar
file:/Users/charlie/.gvm/groovy/current/lib/xstream-1.4.7.jar
请注意,第一个jar文件mysql jar文件已添加到类加载器中,但未添加第二个jar文件oracle jar文件。我也试过两次使用-cp参数:
groovyConsole -cp ~/lib/compile/jar/mysql-connector-java-5.1.32.jar -cp ~/lib/compile/jar/ojdbc6-11.2.0.3.jar
但是这只是因为错误而失败了。除了模糊的提示之外,文档显然没有任何指导,因为它的工作原理就像Java一样。因此,为什么它的第一次尝试如此令人沮丧并没有开箱即用。
我还尝试使用Script>启动groovyConsole后添加Jar文件;将Jar添加到类路径菜单选项,但它不添加任何jar文件。
那么为什么这种工作不能更直接地进行呢?
答案 0 :(得分:0)
Groovy类路径是是Java类路径,您可以使用通配符将所有JAR包含在目录中(请注意,这不是Unix通配符,而是Java的功能,您可能必须在Unix上用单引号引起来,以防止扩展。
groovyConsole -cp $HOME/lib/compile/jar/*
这使我花了很长时间才找到:https://docs.oracle.com/javase/8/docs/technotes/tools/windows/classpath.html#A1100762