2

我正在尝试我的第一个 groovy JMS 示例:也看过这篇文章。这样做了,但 Class 仍然没有解决。

@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()
    }
}
4

2 回答 2

2

难道你只需要添加

import org.apache.activemq.ActiveMQConnectionFactory

行后,@Grab行前class GroovyJMSExample {

于 2013-10-30T11:14:11.323 回答
0

#groovy在 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()
    }
} 
于 2015-03-09T11:36:41.107 回答