使用新的 Groovy Grape 功能会导致“无法解析类” 错误

发布于 2024-07-06 08:21:13 字数 745 浏览 5 评论 0原文

我尝试在 Groovy 1.6-beta-2 中使用新的 Groovy Grape 功能,但出现错误信息;

unable to resolve class com.jidesoft.swing.JideSplitButton

运行普通示例时,从 Groovy 控制台 (/opt/groovy/groovy-1.6-beta-2/bin/groovyConsole) ;

import com.jidesoft.swing.JideSplitButton
@Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,)')
public class TestClassAnnotation {
    public static String testMethod () {
        return JideSplitButton.class.name
    }
}

我什至尝试运行葡萄命令行工具以确保导入库。 像这样;

 $ /opt/groovy/groovy-1.6-beta-2/bin/grape install com.jidesoft jide-oss

这确实可以很好地安装库。 如何从 groovyConsole 正确运行/编译代码?

I've tried to use the new Groovy Grape capability in Groovy 1.6-beta-2 but I get an error message;

unable to resolve class com.jidesoft.swing.JideSplitButton

from the Groovy Console (/opt/groovy/groovy-1.6-beta-2/bin/groovyConsole) when running the stock example;

import com.jidesoft.swing.JideSplitButton
@Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,)')
public class TestClassAnnotation {
    public static String testMethod () {
        return JideSplitButton.class.name
    }
}

I even tried running the grape command line tool to ensure the library is imported. Like this;

 $ /opt/groovy/groovy-1.6-beta-2/bin/grape install com.jidesoft jide-oss

which does install the library just fine. How do I get the code to run/compile correctly from the groovyConsole?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

柒七 2024-07-13 08:21:13

在制定启动/终止开关例程时仍然存在一些问题。 对于 Beta-2,首先在它自己的脚本中执行此操作:

groovy.grape.Grape.initGrape()

您将遇到的另一个问题涉及使用无界上限的乐趣。 Jide-oss 从 2.3.0 开始一直将其代码编译为 Java 6 字节码,因此您需要在 Java 6 中运行控制台(无论如何,这正是您想要为 Swing 做的事情)或设置上限范围,像这样

import com.jidesoft.swing.JideSplitButton

@Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,2.3.0)')
public class TestClassAnnotation {
    public static String testMethod () {
        return JideSplitButton.class.name
    }
}

new TestClassAnnotation().testMethod()

There is still some kinks in working out the startup/kill switch routine. For Beta-2 do this in it's own script first:

groovy.grape.Grape.initGrape()

Another issue you will run into deals with the joys of using an unbounded upper range. Jide-oss from 2.3.0 onward has been compiling their code to Java 6 bytecodes, so you will need to either run the console in Java 6 (which is what you would want to do for Swing anyway) or set an upper limit on the ranges, like so

import com.jidesoft.swing.JideSplitButton

@Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,2.3.0)')
public class TestClassAnnotation {
    public static String testMethod () {
        return JideSplitButton.class.name
    }
}

new TestClassAnnotation().testMethod()
羁拥 2024-07-13 08:21:13

我终于让它适用于 Groovy Shell(1.6.5,JVM:1.6.0_13)。 这应该被更好地记录下来。

首先在命令行...

葡萄安装org.codehaus.groovy.modules.http-builder http-builder 0.5.0-RC2

然后在 groovysh 中...

groovy:000> import groovy.grape.Grape
groovy:000> Grape.grab(group:'org.codehaus.groovy.modules.http-builder', module:'http-builder', version:'0.5.0-RC2')
groovy:000> def http= new groovyx.net.http.HTTPBuilder('http://rovio')
===> groovyx.net.http.HTTPBuilder@91520

@grab 在文件中使用比在 shell 中使用更好。

I finally got it working for Groovy Shell (1.6.5, JVM: 1.6.0_13). This should be documented better.

First at the command line...

grape install org.codehaus.groovy.modules.http-builder http-builder 0.5.0-RC2

Then in groovysh...

groovy:000> import groovy.grape.Grape
groovy:000> Grape.grab(group:'org.codehaus.groovy.modules.http-builder', module:'http-builder', version:'0.5.0-RC2')
groovy:000> def http= new groovyx.net.http.HTTPBuilder('http://rovio')
===> groovyx.net.http.HTTPBuilder@91520

The @grab is better used in a file than the shell.

‖放下 2024-07-13 08:21:13

好的。 看起来这是一个简短的工作演示(从 groovyConsole 运行),

groovy.grape.Grape.initGrape()
@Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,2.3.0)')
public class UsedToExposeAnnotationToComplier {}
com.jidesoft.swing.JideSplitButton.class.name

运行时会产生

结果:“com.jidesoft.swing.JideSplitButton”

非常酷!

Ok. Seems like this a short working demo (running from the groovyConsole)

groovy.grape.Grape.initGrape()
@Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,2.3.0)')
public class UsedToExposeAnnotationToComplier {}
com.jidesoft.swing.JideSplitButton.class.name

When run it produces

Result: "com.jidesoft.swing.JideSplitButton"

Very cool!!

人间不值得 2024-07-13 08:21:13

导入语句必须出现在抓取之后

诗。 抓取后必须至少存在一个导入语句

@Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,)')
import com.jidesoft.swing.JideSplitButton
public class TestClassAnnotation {
    public static String testMethod () {
        return JideSplitButton.class.name
    }
}

The import statement must appear after the grabs.

Ps. At least one import statement must exists after the grabs

@Grab(group='com.jidesoft', module='jide-oss', version='[2.2.1,)')
import com.jidesoft.swing.JideSplitButton
public class TestClassAnnotation {
    public static String testMethod () {
        return JideSplitButton.class.name
    }
}
2024-07-13 08:21:13

使用最新 RC-2 的不同示例(注意:Grab 注释 createEmptyInts):

// create and use a primitive array
import org.apache.commons.collections.primitives.ArrayIntList

@Grab(group='commons-primitives', module='commons-primitives', version='1.0')
def createEmptyInts() { new ArrayIntList() }

def ints = createEmptyInts()
ints.add(0, 42)
assert ints.size() == 1
assert ints.get(0) == 42

Different example using latest RC-2 (note: Grab annotates createEmptyInts):

// create and use a primitive array
import org.apache.commons.collections.primitives.ArrayIntList

@Grab(group='commons-primitives', module='commons-primitives', version='1.0')
def createEmptyInts() { new ArrayIntList() }

def ints = createEmptyInts()
ints.add(0, 42)
assert ints.size() == 1
assert ints.get(0) == 42
∝单色的世界 2024-07-13 08:21:13

另一个例子(注:Grab注释了getHtml):

// find the PDF links in the Java 1.5.0 documentation
@Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='0.9.7')
def getHtml() {
    def parser = new XmlParser(new org.ccil.cowan.tagsoup.Parser())
    parser.parse("http://java.sun.com/j2se/1.5.0/download-pdf.html")
}
html.body.'**'[email protected](~/.*\.pdf/).each{ println it }

Another example (note: Grab annotates getHtml):

// find the PDF links in the Java 1.5.0 documentation
@Grab(group='org.ccil.cowan.tagsoup', module='tagsoup', version='0.9.7')
def getHtml() {
    def parser = new XmlParser(new org.ccil.cowan.tagsoup.Parser())
    parser.parse("http://java.sun.com/j2se/1.5.0/download-pdf.html")
}
html.body.'**'[email protected](~/.*\.pdf/).each{ println it }
衣神在巴黎 2024-07-13 08:21:13

另一个例子(注意:Grab注释了getFruit):

// Google Collections example
import com.google.common.collect.HashBiMap
@Grab(group='com.google.code.google-collections', module='google-collect', version='snapshot-20080530')
def getFruit() { [grape:'purple', lemon:'yellow', orange:'orange'] as HashBiMap }
assert fruit.inverse().yellow == 'lemon'

Another example (note: Grab annotates getFruit):

// Google Collections example
import com.google.common.collect.HashBiMap
@Grab(group='com.google.code.google-collections', module='google-collect', version='snapshot-20080530')
def getFruit() { [grape:'purple', lemon:'yellow', orange:'orange'] as HashBiMap }
assert fruit.inverse().yellow == 'lemon'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文