Исключение в основном потоке java.lang.NoClassDefFoundError: org / apache / thrift / transport / TTransportException

Я новичок в Cassandra, и я пытаюсь создать семейство столбцов и суперколонок с помощью приведенной ниже программы в Eclipse:

import java.util.Arrays;
import java.util.List;

import me.prettyprint.cassandra.model.BasicColumnDefinition;
import me.prettyprint.cassandra.model.BasicColumnFamilyDefinition;
import me.prettyprint.cassandra.serializers.StringSerializer;
import me.prettyprint.cassandra.service.ThriftCfDef;
import me.prettyprint.hector.api.Cluster;
import me.prettyprint.hector.api.ddl.ColumnFamilyDefinition;
import me.prettyprint.hector.api.ddl.ColumnIndexType;
import me.prettyprint.hector.api.ddl.ColumnType;
import me.prettyprint.hector.api.ddl.ComparatorType;
import me.prettyprint.hector.api.ddl.KeyspaceDefinition;
import me.prettyprint.hector.api.exceptions.HectorException;
import me.prettyprint.hector.api.factory.HFactory;

public class HectorTutorial {

    private static final String TEST_KEYSPACE = "TestKeyspace";
    private static final String TEST_CF= "TestColumnFamily";
    private static final String TEST_SUPER= "TestSuperColumn";

    private static StringSerializer stringSerializer = StringSerializer.get();

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

        Cluster cluster = HFactory.getOrCreateCluster("TestCluster", "localhost:9160");

        try {
            if ( cluster.describeKeyspace(TEST_KEYSPACE ) != null ) {
              cluster.dropKeyspace(TEST_KEYSPACE );
            }

            BasicColumnDefinition columnDefinition = new BasicColumnDefinition();
            columnDefinition.setName(stringSerializer.toByteBuffer("TestColumn"));
            columnDefinition.setIndexName("TestColumn_idx ");
            columnDefinition.setIndexType(ColumnIndexType.KEYS);
            columnDefinition.setValidationClass(ComparatorType.LONGTYPE.getClassName());

            BasicColumnFamilyDefinition columnFamilyDefinition = new BasicColumnFamilyDefinition();
            columnFamilyDefinition.setKeyspaceName(TEST_KEYSPACE );
            columnFamilyDefinition.setName(TEST_CF);
            columnFamilyDefinition.addColumnDefinition(columnDefinition);

            BasicColumnFamilyDefinition superCfDefinition = new BasicColumnFamilyDefinition();
            superCfDefinition.setKeyspaceName(TEST_KEYSPACE );
            superCfDefinition.setName(TEST_SUPER);
            superCfDefinition.setColumnType(ColumnType.SUPER);

            ColumnFamilyDefinition cfDefStandard = new ThriftCfDef(columnFamilyDefinition);
            ColumnFamilyDefinition cfDefSuper = new ThriftCfDef(superCfDefinition);

            KeyspaceDefinition keyspaceDefinition = 
                HFactory.createKeyspaceDefinition(TEST_KEYSPACE , "org.apache.cassandra.locator.SimpleStrategy", 
                    1, Arrays.asList(cfDefStandard, cfDefSuper));

            cluster.addKeyspace(keyspaceDefinition);

           /* Below Code show your Keyspace Schema */

            List<KeyspaceDefinition> keyspaces = cluster.describeKeyspaces();
            for (KeyspaceDefinition kd : keyspaces) {
                if ( kd.getName().equals(TEST_KEYSPACE ) ) {
                    System.out.println("Name: " +kd.getName());
                    System.out.println("RF: " +kd.getReplicationFactor());
                    System.out.println("strategy class: " +kd.getStrategyClass());
                    List<ColumnFamilyDefinition> cfDefs = kd.getCfDefs();
                    for (ColumnFamilyDefinition def : cfDefs) {
                      System.out.println("  CF Type: " +def.getColumnType());
                      System.out.println("  CF Name: " +def.getName());
                      System.out.println("  CF Metadata: " +def.getColumnMetadata());  
                    }                                        
                } 
            }                        
        } catch (HectorException he) {
            he.printStackTrace();
        }
        cluster.getConnectionManager().shutdown(); 
    }
}

Когда я пытаюсь выполнить программу, я получаю следующее исключение:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/thrift/transport/TTransportException
    at me.prettyprint.cassandra.connection.factory.HThriftClientFactoryImpl.createClient(HThriftClientFactoryImpl.java:28)
    at me.prettyprint.cassandra.connection.ConcurrentHClientPool.createClient(ConcurrentHClientPool.java:147)
    at me.prettyprint.cassandra.connection.ConcurrentHClientPool.<init>(ConcurrentHClientPool.java:53)
    at me.prettyprint.cassandra.connection.RoundRobinBalancingPolicy.createConnection(RoundRobinBalancingPolicy.java:67)
    at me.prettyprint.cassandra.connection.HConnectionManager.<init>(HConnectionManager.java:67)
    at me.prettyprint.cassandra.service.AbstractCluster.<init>(AbstractCluster.java:67)
    at me.prettyprint.cassandra.service.ThriftCluster.<init>(ThriftCluster.java:21)
    at me.prettyprint.hector.api.factory.HFactory.createCluster(HFactory.java:197)
    at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:144)
    at me.prettyprint.hector.api.factory.HFactory.getOrCreateCluster(HFactory.java:133)
    at HectorTutorial.main(HectorTutorial.java:27)
Caused by: java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransportException
    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)

Я включил все jar-файлы Hector api в путь к классам и не знаю, что вызывает эту ошибку. Может кто-нибудь объяснить причину ошибки?


person Aarish Ramesh    schedule 13.06.2014    source источник
comment
У вас есть libthrift-<version>.jar на пути к классам?   -  person Ralf    schedule 16.06.2014
comment
у меня не было этого раньше .. я поместил его в путь к классам, и теперь он работает нормально .. спасибо   -  person Aarish Ramesh    schedule 16.06.2014


Ответы (2)


Похоже, вам не хватает некоторых сторонних библиотек (в данном случае Thrift, который, как мне кажется, содержит класс TTransportException) . Добавьте также все необходимые библиотеки в свой путь к классам, и давайте посмотрим, поможет ли это.

person rlegendi    schedule 13.06.2014

Проверьте свои «Конфигурации запуска / отладки» в настройках. Определите название «основного класса», который вы используете. Щелкните, чтобы выбрать имя вашего текущего класса. Подать заявление. Ok.

person Phil    schedule 25.02.2015