How to remove Roster or Friend in xmpp server

In previous post we have learn how to add roster in xmpp.  Now we will see xmpp example for remove roster from roster list of any user. For  first you should  add roster in roster list of user. Now We get roster list of user and compare jabber id of roster and remove it using  removeEntry( RosterEntry ) method  . After remove roster you check roster using this article How to get roster of jabber id in xmpp server .

import java.util.Collection;

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterEntry;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException;

public class RemoveRoster {

public static void main(String[] args) {

AddRoster addRoster = new AddRoster();

XMPPConnection connection = addRoster.Connect();
try {
Roster roster = connection.getRoster();
String removeJID = "";
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries) {
// remove roster whith removeJID
if (removeJID.equals(entry.getUser())) {


} catch (XMPPException e) {


public XMPPConnection Connect() {

ConnectionConfiguration config = new ConnectionConfiguration(
"localhost", 5222);

* ConnectionConfiguration config = new ConnectionConfiguration(
* "", 5222);
XMPPConnection connection = new XMPPConnection(config);
try {
} catch (XMPPException e) {

return connection;


you can see more interesting openfire and smack api example

Leave a Reply

Your email address will not be published. Required fields are marked *

68 − 59 =