java - 包 org.apache.commons 不存在

标签 java apache classpath javac

我喜欢使用 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  };

我在 jdk7 上工作,在 Windows Xp 上,从命令行运行

我愿意:

  • 添加到我的源文件

    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
    

我还有一个谜

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

谁知道会发生什么?我真的需要帮助。

注意:

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.

非常感谢你们的高超技能,程序员们!


这是一个简短的演示:

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

最佳答案

问题是:

import org.apache.commons.math3;

那是在尝试导入一个 - 你不能那样做。您必须使用通配符导入:

import org.apache.commons.math3.*;

或导入特定类型:

import org.apache.commons.math3.SomeTypeHere;

在你的情况下,这听起来像是你真正想要的:

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

我已经尝试了一个示例类,只是导入和从 Apache 下载的 jar 文件,它工作正常。

关于java - 包 org.apache.commons 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20844631/

相关文章:

java - 通过套接字传输文件时出现 EOFException 或 SocketException : Socket is closed,

apache - Aptana Studio Apache Tomcat 支持

php - 如何在 PHP 中使用 file_get_contents 修复 404 错误?

eclipse - 如何在 Eclipse 中修改类路径?

java - 无法从类路径获取文件(使用 NIO2)

java - 无法对基本类型 int 调用 getUsers(String)

java - 使用 parallelStream().reduce() 时的错误结果

java - 多接口(interface)机中的 MulticastSocket.setInterface - 如何使用?

php - 如何检查 php 以什么用户身份运行?

java - InputStreamReader ClassPath 处的 NULL 指针