OpenJMS

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #1

    OpenJMS

    Can i write a chat application on OpenJMS in eclipse?
    If yes what libs should i add to java build path?

    Could you also look at my other post (dont want to double) titled server compilation problem which is actually rmic compilation problem please :)
    Last edited by oll3i; May 17 '07, 06:06 PM. Reason: typo
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #2
    i have sender and receiver classes


    How do i run them using OpenJMS?

    what is the -cp for?
    and i get another exception when i run it :( and i dont know if i do it right ?!
    D:\JAVA_P~1\CHA T1>java -cp openjms-0.7.7-beta-1.jar;.; Sender queue1 "ala"
    Exception in thread "main" java.lang.NoCla ssDefFoundError : javax/jms/JMSExceptio
    n
    [code=java]


    import javax.naming.*;
    import javax.jms.*;

    public class Sender {

    public static void main(String[] args) {

    Connection con = null;
    try {
    Context ctx = new InitialContext( );
    ConnectionFacto ry factory = (ConnectionFact ory) ctx.lookup("Con nectionFactory" );
    String admDestName = args[0];
    Destination dest = (Destination) ctx.lookup(admD estName);
    con = factory.createC onnection();
    Session ses = con.createSessi on(false, Session.AUTO_AC KNOWLEDGE);
    MessageProducer sender = ses.createProdu cer(dest);
    con.start();
    TextMessage msg = ses.createTextM essage();

    System.out.prin tln("Enter a word.");



    msg.setText(arg s[1]);
    sender.send(msg );
    System.out.prin tln("Sender sent msg: " + args[1]);
    } catch (Exception exc) {
    exc.printStackT race();
    System.exit(1);
    } finally {
    if (con != null) {
    try {
    con.close();
    } catch (JMSException exc) {
    System.err.prin tln(exc);
    }
    }
    }
    System.exit(0);
    }
    }



    import javax.naming.*;
    import javax.jms.*;

    public class Receiver {

    public static void main(String[] args) {
    Connection con = null;
    try {
    Context ctx = new InitialContext( );
    ConnectionFacto ry factory = (ConnectionFact ory) ctx.lookup("Con nectionFactory" );
    String admDestName = args[0];
    Destination dest = (Destination) ctx.lookup(admD estName);
    con = factory.createC onnection();
    Session ses = con.createSessi on(false, Session.AUTO_AC KNOWLEDGE);
    MessageConsumer receiver = ses.createConsu mer(dest);

    con.start();
    System.out.prin tln("Receiver started");
    Message msg = receiver.receiv e();
    if (msg instanceof TextMessage) {
    TextMessage text = (TextMessage) msg;
    System.out.prin tln("Received: " + text.getText()) ;
    } else if (msg != null) {
    System.out.prin tln("Received non text message");
    }
    } catch (Exception exc) {
    exc.printStackT race();
    System.exit(1);
    } finally {
    if (con != null) {
    try {
    con.close();
    } catch (JMSException exc) {
    System.err.prin tln(exc);
    }
    }
    }
    System.exit(0);
    }
    }



    [/code]

    Comment

    Working...