简体   繁体   English

软件包org.apache.commons不存在

[英]package org.apache.commons does not exist

I'd love to use EnumeratedIntegerDistribution() from org.apache.commons.math3.distribution , to get discrete probabilities distribution 我很想使用org.apache.commons.math3.distribution EnumeratedIntegerDistribution()来获取离散概率分布

int[] nums_to_generate          = new int[]    { -1,   1,    0  };
double[] discrete_probabilities = new double[] { 0.4, 0.4, 0.2  };

I'm working wiht jdk7 , on windows Xp, running from Command Line 我正在Windows XP的jdk7上运行,从命令行运行

I do: 我做:

  • add to my source file 添加到我的源文件

     import org.apache.commons.math3; 
  • download commons-math3-3.2 and unpackage it to my current folder 下载commons-math3-3.2并将其解压缩到我当前的文件夹中
  • compile my source with the classpath: (either) 用类路径编译我的源代码:

     javac -cp ./commons-math3-3.2/commons-math3-3.2.jar:. ConflictsAnimation.java javac -cp commons-math3-3.2/commons-math3-3.2.jar ConflictsAnimation.java 

Still I've got a mysterious 还是我有一个神秘的

    "error: package org.apache.commons does not exist"

Who knows what happens ? 谁知道会发生什么? I really need a help. 我真的需要帮助

Note: 注意:

compilation (and run) is OK without the classpath and without the import of "apache" and call to numeratedIntegerDistribution(). 没有类路径,也没有导入“ apache”和对numeratedIntegerDistribution()的调用,编译(和运行)就可以了。

compilation with the classpath and without the "appache"s give nonsense errors. 带有类路径但不带“ appache”的编译会产生无意义的错误。

Thanks a lot in advance for your great skills, the programmers! 预先感谢您的出色技能,程序员!


Here is short demonstration: 这是简短的演示:

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

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();  
    } 
}

This is the problem: 这就是问题:

import org.apache.commons.math3;

That's trying to import a package - you can't do that. 尝试导入软件包 -您不能这样做。 You have to either use a wildcard import: 您必须使用通配符导入:

import org.apache.commons.math3.*;

or import a specific type: 或导入特定类型:

import org.apache.commons.math3.SomeTypeHere;

In your case it sounds like you actually want: 在您的情况下,听起来像您实际上想要的:

import org.apache.commons.math3.distribution.EnumeratedIntegerDistribution;

I've tried a sample class with just that import and the jar file downloaded from Apache, and it works fine. 我已经尝试了一个示例类,其中仅包含该导入和从Apache下载的jar文件,并且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM