my dog learned polymorphism
The moose likes EJB and other Java EE Technologies and the fly likes OpenJMS - HELP!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "OpenJMS - HELP!!!" Watch "OpenJMS - HELP!!!" New topic

OpenJMS - HELP!!!

Jessica Henry

Joined: Oct 28, 2004
Posts: 4
Hi,I'm new to OpenJMS. Pls help me...

I've dl j2ee, set classpath JAVA_HOME, J2EE_HOME.
I am new to it. So i start working on the examples. There's simpleSender tt sends bytesMessage. I modify the codes to send TextMessage. When Compile, I hv errors:

C:\openjms\src\examples\openjms\examples\client\console\ package javax.jms does not exist
import javax.jms.TextMessage;

This is the code i hv modify:


package openjms.examples.client.console;

import java.util.Date;
import java.util.Random;
import java.lang.String;

import javax.naming.Context;

import javax.jms.TextMessage;
import javax.jms.DeliveryMode;
import javax.jms.Queue;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSender;
import javax.jms.QueueSession;
import javax.jms.Session;
import javax.jms.QueueConnectionFactory;

import org.exolab.jms.util.CommandLine;

* The simple publisher application simply grabs a connection and a session.
* It then creates a queue and begins to sends messages. The application
* expects a queue name to be specified on the command line.

public class SimpleSender {

public static void main(String[] args) {
CommandLine cmdline = new CommandLine(args);
if (cmdline.exists("help") || !cmdline.exists("queue")) {
} else {

boolean summary = cmdline.exists("summary");

try {
// connect to the JNDI server and get a reference to the
// root context
Context context = ContextHelper.getContext(cmdline);

// lookup the connection factory from the context
String factoryName = cmdline.value(
"factory", "JmsQueueConnectionFactory");
QueueConnectionFactory factory = (QueueConnectionFactory)

QueueConnection connection = factory.createQueueConnection();

QueueSession session = connection.createQueueSession(

// if the persistent flag is not specified then create the
// queue object otherwise look it up
String queueName = cmdline.value("queue");
Queue queue = null;
if (cmdline.exists("persistent")) {
queue = (Queue) context.lookup(queueName);
} else {
queue = (Queue) session.createQueue(queueName);

QueueSender sender = session.createSender(queue);

// check the number of iterations that have been specified
// on the command line. If it has not yet been specified
// then default to 10.
int count = Integer.parseInt(cmdline.value("count", "10"));

// check if a sleep has been specified
int sleep = Integer.parseInt(cmdline.value("sleep", "0"));

// check if message time-to-live has been specified
long timeToLive = Integer.parseInt(cmdline.value("ttl", "0"));

// determine if the delivery mode should be persistent or
// non persistent
int deliveryMode = DeliveryMode.NON_PERSISTENT;
if (cmdline.exists("persistent")) {
deliveryMode = DeliveryMode.PERSISTENT;

// retrieve the message size
int size = Integer.parseInt(cmdline.value("size", "10000"));

// create a message
Random rand = new Random((new Date()).getTime());
for (int index = 0; index < count; index++) {
char[] buf = new char[size];
TextMessage message = session.createTextMessage();
message.writeChar(buf, 0, buf.length);
int priority = Math.abs(rand.nextInt() % 10);
sender.send(message, deliveryMode, priority, timeToLive);

if (!summary) {
System.out.println("Publishing " + message);

if (sleep > 0) {
try {
} catch (Exception ignore) {

// close the connection

if (summary) {
System.err.println("The sender has sent " + count +
" messages to queue " + queueName);
} catch (Exception exception) {

* Print out information on running this sevice
static protected void usage() {
PrintStream out = System.out;

out.println("usage: java " + SimpleSender.class.getName() +
" [options]\n");
out.println(" -queue <name> queue to send messages to.\n");
out.println(" -persistent " +
"specifies persistent delivery mode.\n");
out.println(" -mode <tcp | tcps | rmi | http | https>");
out.println(" specifies the connection protocol." +
" Defaults to 'rmi'.\n");
out.println(" -size <num> size of messages (defaults to 10K).\n");
out.println(" -jndiport <num> port where the jndi server runs.\n");
out.println(" -jndihost <host> host where jndi server runs.\n");
out.println(" -count <num> number of messages to publish.\n");
out.println(" -sleep <num> time to sleep b/w each send (ms).\n");
out.println(" -help displays this screen.\n");


Pls tell me where i hv done wrong. :roll:
rakkesh kumar
Ranch Hand

Joined: Oct 06, 2004
Posts: 37
you should add jms.jar file in your classpath
Jessica Henry

Joined: Oct 28, 2004
Posts: 4
Hi,I followed what u told me. add jms.jar in my classpath but i still can't get it work.

classpath - "C:\j2sdkee1.3.1\lib\jms.jar"

is there something tt i am missing.pls advice me. thanks
Jessica Henry

Joined: Oct 28, 2004
Posts: 4
Sorry, I hv made another changes.I think this is the correct one.

classpath = C:\opemjms\lib\jms-1.0.2a.jar

pls advice me.thanks
Jessica Henry

Joined: Oct 28, 2004
Posts: 4
I dun really understand. currently i'm using Textpad to compile my file, what do u use to compile your file with?did u use command-prompt to compile?

Mind telling me in more details? thank u!

Maybe the steps tt u took to set up the environment for J2EE?
I agree. Here's the link:
subject: OpenJMS - HELP!!!
It's not a secret anymore!