Using new Groovy Grape capability results in "unable to resolve class" error
Asked Answered
M

7

13

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?

Maricamarice answered 10/10, 2008 at 17:49 Comment(0)
C
5

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()
Corticosteroid answered 11/10, 2008 at 18:24 Comment(0)
C
5

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.

Cultivable answered 27/10, 2009 at 6:6 Comment(0)
M
2

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!!

Maricamarice answered 11/10, 2008 at 18:50 Comment(1)
This worked great for me. The empty class is key. Couple of points... 1/ I didn't need the initGrape() line (using groovy 1.7x or 1.8x).. 2/ If you are behind a proxy make sure to add your proxy settings -Dhttp.proxyHost=<proxyhost> -Dhttp.proxyPort=<proxyPort>... I add them to my startGroovy.sh|batBunn
A
0

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
    }
}
Abixah answered 9/12, 2013 at 14:38 Comment(0)
S
-1

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
Swetlana answered 23/1, 2009 at 14:58 Comment(2)
Examples stolen from groovy.codehaus.org/Grape. (copied exactly) Also, it does not answer the question.Whelk
I agree. Please refer people to correct answers if you find them elsewhere on the web. Provide a link. Please don't take credit for other people's work without attribution.Encase
S
-1

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 }
Swetlana answered 31/1, 2009 at 14:33 Comment(1)
Examples stolen from groovy.codehaus.org/Grape. (copied exactly) Also, it does not answer the question.Whelk
S
-3

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'
Swetlana answered 31/1, 2009 at 14:59 Comment(1)
Examples stolen from groovy.codehaus.org/Grape. (copied exactly) Also, it does not answer the question.Whelk

© 2022 - 2024 — McMap. All rights reserved.