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

[4974 byte] By [oll3ia] at [2007-11-27 4:55:07]
# 1
i found that it has something to do with the classpath but i didnt found the solution to my problem :(
oll3ia at 2007-7-12 10:09:58 > top of Java-index,Java Essentials,Java Programming...
# 2
Are you sure j2ee.jar is in your classpath?
Peetzorea at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 3

my CLASSPATH is set

.;C:\ProgramFiles\Java\jre1.6.0\bin;C:\Program Files\Altova\xmlspy\XMLSpyInterface.jar;%J2EE_HOME%\lib\j2ee.jar;C:\Program Files\db4o-6.1\db4o-6.1-java5.jar;%CLASSPATH%;

BTW when i try to start openJMS i get

C:\OPENJMS\OPENJMS\BIN>startup.bat

The JAVA_HOME environment variable is not set correctly.

This is required to run OpenJMS.

and my JAVA_HOME is set

C:\Program Files\Java\jre1.6.0; should that be the path to jdk or jre?

thank you

oll3ia at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 4
okey the openJMS works but still the classpath is not set correctly
oll3ia at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 5
> okey the openJMS works but still the classpath is not> set correctlyHow do you know?
georgemca at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 6
i can start OpenJMS but i when i run the Sender i get exception i dont know how to set the classpath to make it work
oll3ia at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 7
You see how you're adding openJms to your runtime classpath, with the -cp flag? You also need to include the jar that has the JMS interfaces in
georgemca at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 8
i dont know which one that is ?, openjms-0.7.7-beta-1.jar that's what i was adding and it doesnt work?
oll3ia at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 9

> i dont know which one that is ?,

> openjms-0.7.7-beta-1.jar that's what i was adding

> and it doesnt work?

You need to also include another jar, which contains the JMS API itself. I can't remember whether that jar is j2ee.jar or another. Have a wander around the API downloads section, it's there somewhere

georgemca at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 10
Have you tried enclosing your classpath in double quotes?
Peetzorea at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 11
but you mean environment variable ? or when i run it
oll3ia at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 12
he means at the command line... otherwise you'll have problems with space in winblows file names Spaces in file names is the silliest idea since \13\10.Message was edited by: corlettk can't type
corlettka at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...
# 13
no it doesnt help
oll3ia at 2007-7-12 10:09:59 > top of Java-index,Java Essentials,Java Programming...