javax.jms.TopicConnectionFactory not bound的问题?

04-03-05 ijava

在JBOSS\jboss-3.0.4_tomcat-4.0.6环境下做一个最简单的JMS

Exception in thread "main" javax.naming.NameNotFoundException: javax.jms.TopicConnectionFactory not bound

运行以下的就报这个错。

这个包有啊,怎么才能绑定这个啊???

E:\ejbstudy\jms\classes>java -Djava.security.policy=../java.policy -Djava.naming

.factory.initial=org.jnp.interfaces.NamingContextFactory -Djava.naming.provider.

url=localhost examples.Client

examples.Client

__

package examples;

import javax.naming.*;

import javax.jms.*;

import java.util.*;

public class Client {

public static void main (String[] args) throws Exception {

// Initialize JNDI

Context ctx = new InitialContext(System.getProperties());

// 1: Lookup ConnectionFactory via JNDI

TopicConnectionFactory factory =

(TopicConnectionFactory)

ctx.lookup("javax.jms.TopicConnectionFactory");

// 2: Use ConnectionFactory to create JMS connection

TopicConnection connection =

factory.createTopicConnection();

// 3: Use Connection to create session

TopicSession session = connection.createTopicSession(

false, Session.AUTO_ACKNOWLEDGE);

// 4: Lookup Desintation (topic) via JNDI

Topic topic = (Topic) ctx.lookup("testtopic");

// 5: Create a Message Producer

TopicPublisher publisher = session.createPublisher(topic);

// 6: Create a text message, and publish it

TextMessage msg = session.createTextMessage();

msg.setText("This is a test message.");

publisher.publish(msg);

}

}--

benzuo
2004-03-23 16:53

look up "ConnectionFactory"