openJMS
i have sender and receiver classes
what is the -cp for?
and i get exception when i run it :( and i dont know if i do it right ?!
D:\JAVA_P~1\CHAT1>java -cp openjms-0.7.7-beta-1.jar;.; Sender queue1 "something to send"
Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/JMSExceptio
n
import javax.naming.*;
import javax.jms.*;
publicclass Sender{
publicstaticvoid main(String[] args){
Connection con =null;
try{
Context ctx =new InitialContext();
ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
String admDestName = args[0];
Destination dest = (Destination) ctx.lookup(admDestName);
con = factory.createConnection();
Session ses = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer sender = ses.createProducer(dest);
con.start();
TextMessage msg = ses.createTextMessage();
System.out.println("Enter a word.");
msg.setText(args[1]);
sender.send(msg);
System.out.println("Sender sent msg: " + args[1]);
}catch (Exception exc){
exc.printStackTrace();
System.exit(1);
}finally{
if (con !=null){
try{
con.close();
}catch (JMSException exc){
System.err.println(exc);
}
}
}
System.exit(0);
}
}
import javax.naming.*;
import javax.jms.*;
publicclass Receiver{
publicstaticvoid main(String[] args){
Connection con =null;
try{
Context ctx =new InitialContext();
ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
String admDestName = args[0];
Destination dest = (Destination) ctx.lookup(admDestName);
con = factory.createConnection();
Session ses = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer receiver = ses.createConsumer(dest);
con.start();
System.out.println("Receiver started");
Message msg = receiver.receive();
if (msginstanceof TextMessage){
TextMessage text = (TextMessage) msg;
System.out.println("Received: " + text.getText());
}elseif (msg !=null){
System.out.println("Received non text message");
}
}catch (Exception exc){
exc.printStackTrace();
System.exit(1);
}finally{
if (con !=null){
try{
con.close();
}catch (JMSException exc){
System.err.println(exc);
}
}
}
System.exit(0);
}
}
thank you

