• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

OpenJMS - HELP!!!

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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\SimpleSender.java:16: package javax.jms does not exist
import javax.jms.TextMessage;

This is the code i hv modify:

---------------------------------------------------------------------------

package openjms.examples.client.console;

import java.io.PrintStream;
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")) {
usage();
} 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)
context.lookup(factoryName);

QueueConnection connection = factory.createQueueConnection();
connection.start();

QueueSession session = connection.createQueueSession(
false, Session.CLIENT_ACKNOWLEDGE);

// 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 {
Thread.sleep(sleep);
} catch (Exception ignore) {
}
}
}

// close the connection
connection.close();

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

/**
* 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("options:");
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:
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should add jms.jar file in your classpath
 
Jessica Henry
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic