Java 包 org.apache.commons 不存在

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20844631/
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 04:44:40  来源:igfitidea点击:

package org.apache.commons does not exist

javaapacheclasspathjavac

提问by Galia

I'd love to use EnumeratedIntegerDistribution()from org.apache.commons.math3.distribution, to get discrete probabilities distribution

我很想使用EnumeratedIntegerDistribution()fromorg.apache.commons.math3.distribution来获得离散概率分布

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

我正在使用 jdk7 ,在 Windows Xp 上,从命令行运行

I do:

我愿意:

  • add to my source file

    import org.apache.commons.math3; 
    
  • download commons-math3-3.2 and unpackage it to my current folder
  • 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
    
  • 添加到我的源文件

    import org.apache.commons.math3; 
    
  • 下载 commons-math3-3.2 并将其解压缩到我的当前文件夹
  • 使用类路径编译我的源代码:(或者)

    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().

compilation with the classpath and without the "appache"s give nonsense errors.

编译(和运行)在没有类路径和没有导入“apache”和调用 numeratedIntegerDistribution() 的情况下是可以的。

使用类路径而不使用“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();  
    } 
}

回答by Jon Skeet

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 justthat import and the jar file downloaded from Apache, and it works fine.

我已经尝试了一个示例类,其中仅包含该导入和从 Apache 下载的 jar 文件,并且运行良好。