Java 错误:无法找到或加载主类,Cassandra

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22512840/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 16:11:01  来源:igfitidea点击:

Error: Could not find or load main class, Cassandra

javacassandra

提问by genclik27

I am trying to build Casandra project on a Centos server. I downloaded the file from here.

我正在尝试在 Centos 服务器上构建 Casandra 项目。我从这里下载了文件。

http://apache.bilkent.edu.tr/cassandra/2.0.6/

http://apache.bilkent.edu.tr/cassandra/2.0.6/

Here is the README.txt file

这是 README.txt 文件

This short guide will walk you through getting a basic one node cluster up
and running, and demonstrate some simple reads and writes.

  * tar -zxvf apache-cassandra-$VERSION.tar.gz
  * cd apache-cassandra-$VERSION
  * sudo mkdir -p /var/log/cassandra
  * sudo chown -R `whoami` /var/log/cassandra
  * sudo mkdir -p /var/lib/cassandra
  * sudo chown -R `whoami` /var/lib/cassandra

Note: The sample configuration files in conf/ determine the file-system 
locations Cassandra uses for logging and data storage. You are free to
change these to suit your own environment and adjust the path names
used here accordingly.

Now that we're ready, let's start it up!

  * bin/cassandra -f

As README.txt file suggested I followed these instructions as adapting to my case (I am not root).

由于 README.txt 文件建议我按照这些说明来适应我的情况(我不是 root)。

tar -zxvf apache-cassandra-2.0.6-src.tar.gz
cd apache-cassandra-2.0.6-src
mkdir -p var/log/cassandra
chown -R `whoami` var/log/cassandra
mkdir -p var/lib/cassandra
chown -R `whoami` var/lib/cassandra

Since I am not root on the server, I can not create my files under /varfolder. So, I created new folder varunder apache-cassandra-2.0.6-srcand put my liband logfiles there. Then I followed next instructions from README.txt file.

由于我不是服务器上的 root,因此无法在/var文件夹下创建文件。所以,我在var下面创建了新文件夹apache-cassandra-2.0.6-src并将我的liblog文件放在那里。然后我按照 README.txt 文件中的下一个说明进行操作。

bin/cassandra -f

However whatever I tried it is no good, I always get this error.

然而,无论我尝试过什么都不好,我总是收到这个错误。

Error: Could not find or load main class org.apache.cassandra.service.CassandraDaemon

How can I fix this problem?

我该如何解决这个问题?

My java version

我的java版本

java -version

java version "1.7.0_51"
OpenJDK Runtime Environment (rhel-2.4.4.1.el6_5-x86_64 u51-b02)
OpenJDK 64-Bit Server VM (build 24.45-b08, mixed mode)

EDIT:As an extra informaiton, I tried this instructions on my pc, too. Exactly same thing with README.txt file using sudoand it worked.

编辑:作为额外的信息,我也在我的电脑上尝试了这个说明。与使用 README.txt 文件完全相同sudo并且有效。

回答by Harry

In the cassandra.yamlconfiguration file, change the

cassandra.yaml配置文件中,更改

commitlog_directory
data_file_directories
saved_caches_directory

properties to the path you have specified as they are no longer /var/lib...

您指定的路径的属性,因为它们不再 /var/lib...

You will need to set them to point to wherever the directories actually are.

您需要将它们设置为指向目录实际所在的位置。

回答by Jason C

I see you have downloaded the source package (apache-cassandra-2.0.6-src.tar.gz), but the instructions you posted seem to assume it is already built.

我看到您已经下载了源包 ( apache-cassandra-2.0.6-src.tar.gz),但您发布的说明似乎假定它已经构建。

You need to build the source package before you can use it; there would be a separate set of instructions for that somewhere.

需要先构建源码包才可以使用;在某处会有一套单独的说明。

I suspect you'd rather just run it instead of building it from source. You may have meant to download the binary package apache-cassandra-2.0.6-bin.tar.gzinstead (note "bin", not "src" -- this is a traditional naming convention when separating binaries from source in downloadable archives). With that package you can just run it right out of the box. For the source package you'd need to follow the build instructions to compile cassandra first.

我怀疑您宁愿直接运行它而不是从源代码构建它。您可能打算下载二进制包apache-cassandra-2.0.6-bin.tar.gz(注意“bin”,而不是“src”——这是将二进制文件与可下载档案中的源文件分开时的传统命名约定) . 使用该软件包,您可以立即运行它。对于源包,您需要先按照构建说明编译 cassandra。

I also suspect that you downloaded the binary package on the PC side, which is why it worked there.

我还怀疑您在 PC 端下载了二进制包,这就是它在那里工作的原因。

If you do need to build from source:

如果您确实需要从源代码构建:

  1. Install antand ant-optionalif you do not already have it.
  2. Extract the source archive somewhere, then in the base directory (where build.xmlis):

    ant release
    
  3. Make a cup of coffee (the rattask at the end takes forever).
  4. Binary archives will be created in build, and a built distribution can be found in build/dist.
  1. 安装antant-optional如果您还没有它。
  2. 将源存档解压缩到某处,然后在基本目录中(build.xml是):

    ant release
    
  3. 煮一杯咖啡(最后的rat任务需要永远)。
  4. 二进制档案将buildbuild/dist.

回答by skipy

do a export CASSANDRA_HOME=location of cassandra

做一个出口 CASSANDRA_HOME=cassandra 的位置

should work in 2.0.6 i verified just then without setting that variable and after setting those variables.

应该可以在 2.0.6 中工作,我当时没有设置该变量并在设置这些变量后进行了验证。

$ export CASSANDRA_HOME=/usr/local/cassandra/dsc-cassandra-2.0.6
$ /usr/local/cassandra/dsc-cassandra-2.0.6/bin/cassandra


or
$ cd /usr/local/cassandra/dsc-cassandra-2.0.6
$ export CASSANDRA_HOME=
$ bin/cassandra

in fact you can also set CASSANDRA_HOME= in cassandra-2.0.6 directory. set it to empty value if you are executing the export command from the cassandra directory.

实际上你也可以在 cassandra-2.0.6 目录中设置 CASSANDRA_HOME= 。如果您从 cassandra 目录执行导出命令,请将其设置为空值。

回答by Rahul

I faced exact problem, where I wanted to install cassandra in userspace without any sudo privileges. I did the following

我遇到了确切的问题,我想在没有任何 sudo 权限的用户空间中安装 cassandra。我做了以下

In cassandra.yaml I changed the following config to local path

在 cassandra.yaml 中,我将以下配置更改为本地路径

commitlog_directory
data_file_directories
saved_caches_directory
log4j.appender.R.File

Installed the "bin" tar files for the particular OS env and not the "src" file.

为特定的操作系统环境安装了“bin”tar 文件,而不是“src”文件。

Export CASSANDRA_HOME=/userspace/cassandra-2.x

Now it works fine for me.

现在它对我来说很好用。

回答by Vivek

Path for CASSANDRA_HOME was incorrect for me. After i set the correct path it ran perfectly.

CASSANDRA_HOME 的路径对我来说不正确。在我设置正确的路径后,它完美运行。