apache 公共:ClassNotFoundException [英] apache commons: ClassNotFoundException

查看:25
本文介绍了apache 公共:ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 org.apache.commons.math3.distributionEnumeratedIntegerDistribution() 中受益,如下所示.

I'm trying to benefite from the EnumeratedIntegerDistribution() from org.apache.commons.math3.distribution, as shown below.

我正在使用 jdk7,在 Windows Xp 上,从命令行运行,在一个且唯一的项目文件夹中

I'm working wiht jdk7 , on windows Xp, running from Command Line, in one and only project folder

我愿意:

  • 下载 commons-math3-3.2 并将其解压缩到我的文件夹,即我的 java 所在的文件夹.
  • 编译我的源代码(没有错误没有警告)javac -cp commons-math3-3.2/commons-math3-3.2.jar CheckMe.java
  • 运行 java CheckMe

导入 java.lang.Math.*;导入 org.apache.commons.math3.distribution.EnumeratedIntegerDistribution;

import java.lang.Math.*; import org.apache.commons.math3.distribution.EnumeratedIntegerDistribution;

公开课 CheckMe {

public class CheckMe {

public CheckMe() {

    System.out.println("let us check it out"); 
    System.out.println(generate_rand_distribution (10));
}

private static int[] generate_rand_distribution (int count){
    int[] nums_to_generate          = new int[]    { -1,   1,    0  };
    double[] discrete_probabilities = new double[] { 0.4, 0.4, 0.2  };
    int[] samples = null;

    EnumeratedIntegerDistribution distribution = 
    new EnumeratedIntegerDistribution(nums_to_generate, discrete_probabilities);

    samples = distribution.sample (count);

    return (samples);
}   

public static void main (String args[]) { 
    System.out.println("Main: ");
    CheckMe  animation = new CheckMe();  
} 

}

但是我有:

ClassNotFoundException: org.apache.commons.math3.distribution.EnumeratedIntegerDistribution在第 18 行 - 调用 EnumeratedIntegerDistribution()

ClassNotFoundException: org.apache.commons.math3.distribution.EnumeratedIntegerDistribution at line 18 - the call for EnumeratedIntegerDistribution()

如果我按照刚才的建议跑步(如下):

If I run as I was just advised (below):

    java -cp   commons-math3-3.2/commons-math3-3.2.jar  CheckMe

我得到错误:不可能找到主类CheckMe

I get error: impossible to find the principle class CheckMe

非常感谢您的建议.

推荐答案

编译和运行时都需要指定类路径.所以运行

You need to specify the classpath both when you compile and when you run. So running

java CheckMe.java 

还不够.也应该是

java CheckMe

假设 CheckMe 类不在任何包中.

assuming the class CheckMe is not in any package.

你需要执行

java -cp commons-math3-3.2/commons-math3-3.2.jar CheckMe

指定您的 CheckMe 程序需要的 jars 和其他类.

specifying the jars and other classes your CheckMe program needs.

这篇关于apache 公共:ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆