powered by Jive Software

Sending message

Hi all!

Having some problems installing smack!

My JAVA_HOME = c:\j2sdk1.4.2_03

Path = ANT_HOME%\bin;%JAVA_HOME%\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\S ystem32\Wbem

When I run a simple Jabber Client it cannot find the smack. I put the smack jar files in my Java_Home bin directory not sure if that is right!

Also the same problems with xerces not sure how to install this. Im trying to run the code in chp4 of the Jabber book by iain.

Im running Win XP home! and running JabberD server!

Please Help!

Thanks

Dilip

Dilip,

The easiest way to add JAR files to your classpath is when you’'re running them from the command-line using the -cp flag. Assuming that smack.jar and smackx.jar are in the same directory:

java -cp smack.jar;smackx.jar com.yoursite.MainClass

Xerces is the same story. It will have a set of JAR files that you just need to add to your classpath (usually easiest through the command-line).

Regards,

Matt

Thanks Matt! Seems to work!

I have also got started with some code found on this site!

I seem to be having a problem in creating a sendMessage through the command line. What I want to do is send a Message to a user through the command line. So any text that is typed on the command line will be attached and sent to another Jabber ID. At the moment I have this code that listens to the replys. I have put a test message inside the class that sends a message but I want for the user to type there own messages.

Please Help.

Thanks

Dilip

import org.jivesoftware.smack.*;

import org.jivesoftware.smack.packet.Packet;

import org.jivesoftware.smack.packet.Message;

import org.jivesoftware.smack.filter.*;

public class JabberClient extends Thread implements PacketListener {

public static void main(String [] args) throws Exception {

XMPPConnection connection = new XMPPConnection(“localhost”);

connection.login(“pateldw”, “intel1”);

Chat newChat = connection.createChat(“dilip1@localhost”);

newChat.sendMessage(“This is a Test”);

PacketFilter filter = new PacketTypeFilter(Message.class);

JabberClient listener = new JabberClient();

listener.start();

connection.addPacketListener(listener, filter);

}

public void processPacket(Packet packet) {

Message message = (Message)packet;

System.out.println("From: " + packet.getFrom());

System.out.println("Body: " + message.getBody());

System.out.println("----


");

}

public void run() {

while (true) {

try {

Thread.sleep(10);

}

catch (Exception e) { }

}

}

}

You’‘ll just need to use the System.in input stream to read from the command line. You may want to consult a Java book on command-line programming, but if you run into specific questions about the Smack API, we’'re happy to try to help answer them.

Regards,

Matt