1

I am trying to compile a java file using SMACK for the XMPP libraries. In the folder of the java file i have included a Libs directory including all the *.jar files for SMACK but when i try

javac filename

i get this output:

SmackCcsClient.java:6: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.ConnectionConfiguration;
                             ^
SmackCcsClient.java:7: error: package org.jivesoftware.smack.ConnectionConfiguration does not exist
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
                                                     ^
SmackCcsClient.java:8: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.ConnectionListener;
                             ^
SmackCcsClient.java:9: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.PacketInterceptor;
                             ^
SmackCcsClient.java:10: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.PacketListener;
                             ^
SmackCcsClient.java:11: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.XMPPConnection;
                             ^
SmackCcsClient.java:12: error: package org.jivesoftware.smack does not exist
import org.jivesoftware.smack.XMPPException;
                             ^
SmackCcsClient.java:13: error: package org.jivesoftware.smack.filter does not exist
import org.jivesoftware.smack.filter.PacketTypeFilter;
                                    ^
SmackCcsClient.java:14: error: package org.jivesoftware.smack.packet does not exist
import org.jivesoftware.smack.packet.DefaultPacketExtension;
                                    ^
SmackCcsClient.java:15: error: package org.jivesoftware.smack.packet does not exist
import org.jivesoftware.smack.packet.Message;
                                    ^
SmackCcsClient.java:16: error: package org.jivesoftware.smack.packet does not exist
import org.jivesoftware.smack.packet.Packet;
                                    ^
SmackCcsClient.java:17: error: package org.jivesoftware.smack.packet does not exist
import org.jivesoftware.smack.packet.PacketExtension;
                                    ^
SmackCcsClient.java:18: error: package org.jivesoftware.smack.provider does not exist
import org.jivesoftware.smack.provider.PacketExtensionProvider;
                                      ^
SmackCcsClient.java:19: error: package org.jivesoftware.smack.provider does not exist
import org.jivesoftware.smack.provider.ProviderManager;
                                      ^
SmackCcsClient.java:20: error: package org.jivesoftware.smack.util does not exist
import org.jivesoftware.smack.util.StringUtils;
                                  ^
SmackCcsClient.java:21: error: package org.json.simple does not exist
import org.json.simple.JSONValue;
                      ^
SmackCcsClient.java:22: error: package org.json.simple.parser does not exist
import org.json.simple.parser.ParseException;
                             ^
SmackCcsClient.java:23: error: package org.xmlpull.v1 does not exist
import org.xmlpull.v1.XmlPullParser;
                     ^
SmackCcsClient.java:52: error: cannot find symbol
    XMPPConnection connection;
    ^
  symbol:   class XMPPConnection
  location: class SmackCcsClient
SmackCcsClient.java:53: error: cannot find symbol
    ConnectionConfiguration config;
    ^
  symbol:   class ConnectionConfiguration
  location: class SmackCcsClient
SmackCcsClient.java:306: error: cannot find symbol
    public void connect(String username, String password) throws XMPPException {
                                                                 ^
  symbol:   class XMPPException
  location: class SmackCcsClient
SmackCcsClient.java:58: error: cannot find symbol
    class GcmPacketExtension extends DefaultPacketExtension {
                                     ^
  symbol:   class DefaultPacketExtension
  location: class SmackCcsClient
SmackCcsClient.java:77: error: cannot find symbol
        public Packet toPacket() {
               ^
  symbol:   class Packet
  location: class SmackCcsClient.GcmPacketExtension
SmackCcsClient.java:70: error: method does not override or implement a method from a supertype
        @Override
        ^
SmackCcsClient.java:78: error: cannot find symbol
            return new Message() {
                       ^
  symbol:   class Message
  location: class SmackCcsClient.GcmPacketExtension
SmackCcsClient.java:117: error: cannot find symbol
                GCM_NAMESPACE, new PacketExtensionProvider() {
                                   ^
  symbol:   class PacketExtensionProvider
  location: class SmackCcsClient
SmackCcsClient.java:116: error: cannot find symbol
        ProviderManager.getInstance().addExtensionProvider(GCM_ELEMENT_NAME,
        ^
  symbol:   variable ProviderManager
  location: class SmackCcsClient
SmackCcsClient.java:145: error: cannot find symbol
        Packet request = new GcmPacketExtension(jsonRequest).toPacket();
        ^
  symbol:   class Packet
  location: class SmackCcsClient
SmackCcsClient.java:276: error: cannot find symbol
        return JSONValue.toJSONString(message);
               ^
  symbol:   variable JSONValue
  location: class SmackCcsClient
SmackCcsClient.java:294: error: cannot find symbol
        return JSONValue.toJSONString(message);
               ^
  symbol:   variable JSONValue
  location: class SmackCcsClient
SmackCcsClient.java:307: error: cannot find symbol
        config = new ConnectionConfiguration(GCM_SERVER, GCM_PORT);
                     ^
  symbol:   class ConnectionConfiguration
  location: class SmackCcsClient
SmackCcsClient.java:308: error: cannot find symbol
        config.setSecurityMode(SecurityMode.enabled);
                               ^
  symbol:   variable SecurityMode
  location: class SmackCcsClient
SmackCcsClient.java:319: error: cannot find symbol
        XMPPConnection.DEBUG_ENABLED = true;
        ^
  symbol:   variable XMPPConnection
  location: class SmackCcsClient
SmackCcsClient.java:321: error: cannot find symbol
        connection = new XMPPConnection(config);
                         ^
  symbol:   class XMPPConnection
  location: class SmackCcsClient
SmackCcsClient.java:324: error: cannot find symbol
        connection.addConnectionListener(new ConnectionListener() {
                                             ^
  symbol:   class ConnectionListener
  location: class SmackCcsClient
SmackCcsClient.java:353: error: cannot find symbol
        connection.addPacketListener(new PacketListener() {
                                         ^
  symbol:   class PacketListener
  location: class SmackCcsClient
SmackCcsClient.java:397: error: cannot find symbol
        }, new PacketTypeFilter(Message.class));
               ^
  symbol:   class PacketTypeFilter
  location: class SmackCcsClient
SmackCcsClient.java:397: error: cannot find symbol
        }, new PacketTypeFilter(Message.class));
                                ^
  symbol:   class Message
  location: class SmackCcsClient
SmackCcsClient.java:400: error: cannot find symbol
        connection.addPacketInterceptor(new PacketInterceptor() {
                                            ^
  symbol:   class PacketInterceptor
  location: class SmackCcsClient
SmackCcsClient.java:405: error: cannot find symbol
        }, new PacketTypeFilter(Message.class));
               ^
  symbol:   class PacketTypeFilter
  location: class SmackCcsClient
SmackCcsClient.java:405: error: cannot find symbol
        }, new PacketTypeFilter(Message.class));
                                ^
  symbol:   class Message
  location: class SmackCcsClient
SmackCcsClient.java:447: error: cannot find symbol
    } catch (XMPPException e) {
             ^
  symbol:   class XMPPException
  location: class SmackCcsClient
42 errors

how do i compile this correctly? is there some extra command needed for the smack library?

UPDATE:

i have created the following folder structure:

root
->bin
->src
->lib

I have tried compiling with different javac commands like:

javac -d bin -sourcepath src -cp :lib src/SmackCcsClient.java

I have tried various variations but i keep getting the same output every time.

UPDATE 2:

running the command:

javac -d bin -sourcepath src -cp lib/*.jar src/SmackCcsClient.java

gave the following output:

javac: invalid flag: lib/smack-android-4.1.1-javadoc.jar
Usage: javac <options> <source files>
use -help for a list of possible options

I am following different tutorials but i cannot figure out how to do this correctly.

1 Answer 1

3

A correct command would be (assuming all needed .jar files are actually in the lib/ folder, and all sources are in the src/ folder):

javac -d bin -sourcepath src -cp $(find lib -iname *.jar | xargs | tr " " ":") src/SmackCcsClient.java

The tricky part (within $( )) is building something like a.jar:b.jar:c.jar (no spaces, separated by :) from all the jar-files in the lib/ folder. Your attempt using -cp lib/*.jar failed because there were spaces instead of : separating the jar-files, and javac thought that the second jar-file it found was actually java source that you wanted to compile. And then complained that it did not know how to compile jar-files.

A simpler version (that relies on there being no sub-directories in lib/) is

javac -d bin -sourcepath src -cp $(echo lib/*.jar | tr " " ":") src/SmackCcsClient.java
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you! great explanation! you just made my day

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.