This is the server side code for GCM notification, i have build this successfully on ubuntu using command line by adding gcm-server.jar, but at run time it crashes with exception. I have added the jar in the classpath.
Exception at run time :
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/android /gcm/server/Message$Builder
at geo.sendNotification.sendNow(sendNotification.java:30)
at geo.geosense.main(geosense.java:27)
Caused by: java.lang.ClassNotFoundException: com.google.android.gcm.server.Message$Builder
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
..
.
import org.json.simple.*;
import java.util.*;
import com.google.android.gcm.server.Message.Builder;
import com.google.android.gcm.server.Message;
import com.google.android.gcm.server.Sender;
import com.google.android.gcm.server.Result;
import com.google.android.gcm.server.MulticastResult;
public class sendNotification {
Sender sender = null;
public void sendNotification () // function to send message
{
Sender sender = new Sender("XYZ"); // api key
}
public void sendNow(String deviceID, String msg, String param)
{
Message message = new Message.Builder()
.addData("message", msg)
.addData("parameter one", param)
.build();
try{
Result result = sender.send(message, deviceID, 1);
}
catch ( Exception e )
{
e.printStackTrace();
}
}}
____________________________________________________________________________