2

I am trying my first groovy JMS example: Also seen this post. Did that but still Class not resolved.

@Grab(group='net.sf.gtools.jms', module='JmsCategory', version='0.2')
@Grab(group='org.apache.activemq',module = 'activemq-all', version='5.9.0')
@Grab(group="junit", module="junit", version="4.11")

class GroovyJMSExample {
    def sendMessage() {
        use(JmsCategory) {
            def jms = new ActiveMQConnectionFactory('tcp://localhost:61616')
            jms.connect { c ->
                c.queue("TEST-queue") { q ->
                    def msg = createTextMessage("test")
                    q.send(msg)
                }
            }
        }
    }
    static void main(String[] args) {
        sendMessage()
    }
}
Community
  • 1
  • 1
  • Your example didn't work for me until I added `import net.sf.gtools.jms.JmsCategory` between the `@Grab`s and the class definition. – John Mark Jan 08 '14 at 21:06

2 Answers2

2

Don't you just need to add

import org.apache.activemq.ActiveMQConnectionFactory

After the @Grab lines, and before the class GroovyJMSExample { line?

tim_yates
  • 167,322
  • 27
  • 342
  • 338
  • Absolutely right. I assumed that Grab would locate the classes. Added import ....activemq.*. Moving on to next bug. – user2935846 Nov 02 '13 at 15:28
0

with some (lots) of help from #groovy on freenode IRC:

@Grapes([
        @Grab(group = 'net.sf.gtools.jms', module = 'JmsCategory', version = '0.2'),
        @Grab(group = 'org.apache.activemq', module = 'activemq-all', version = '5.9.0'),
        @Grab(group = "junit", module = "junit", version = "4.11"),
        @Grab(group = 'net.sf.gtools.jms', module = 'JmsCategory', version = '0.2'),
        @Grab(group = 'org.apache.activemq', module = 'activemq-all', version = '5.9.0'),
        @Grab(group = "junit", module = "junit", version = "4.11"),
        @Grab(group = 'net.sf.gtools.jms', module = 'JmsCategory', version = '0.2'),
        @Grab(group = 'org.apache.activemq', module = 'activemq-all', version = '5.9.0'),
        @Grab(group = "junit", module = "junit", version = "4.11"),
        @Grab(group = 'net.sf.gtools.jms', module = 'JmsCategory', version = '0.2'),
        @Grab(group = 'org.apache.activemq', module = 'activemq-all', version = '5.9.0'),
        @Grab(group = "junit", module = "junit", version = "4.11")
])
import net.sf.gtools.jms.JmsCategory
import org.apache.activemq.ActiveMQConnectionFactory

class GroovyJMSExample {
    def static sendMessage() {
        use(JmsCategory) {
            def jms = new ActiveMQConnectionFactory('tcp://localhost:61616')
            jms.connect { c ->
                c.queue("TEST-queue") { q ->
                    def msg = createTextMessage("test")
                    q.send(msg)
                }
            }
        }
    }

    static void main(String[] args) {
        sendMessage()
    }
} 
Thufir
  • 8,216
  • 28
  • 125
  • 273
  • This ActiveMQ producer works fine with the accompanying, remote, [consumer](http://article.gmane.org/gmane.comp.lang.groovy.user/67083). – Thufir Mar 09 '15 at 16:08