运行番石榴的问题 [英] Issue with Running Guava

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

问题描述

我有一个Java文件Test.java(如下),该文件使用Guava的HashMultiMap(从下载http://code.google.com/p/guava-libraries/).我将.java和.jar文件都存储在"C:\ Program Files \ Java \ jdk1.6.0_25 \ bin"中.然后从命令提示符处执行命令:

I have a java file Test.java (below) which uses Guava's HashMultiMap (downloaded from http://code.google.com/p/guava-libraries/). I store both .java and .jar file in "C:\Program Files\Java\jdk1.6.0_25\bin" . And then from command prompt, I execute the commands:

javac -cp guava-11.0.2.jar Test.java

javac -cp guava-11.0.2.jar Test.java

java -cp guava-11.0.2.jar测试

java -cp guava-11.0.2.jar Test

"javac -cp guava-11.0.2.jar Test.java"正在执行并生成一个.class文件.但是,"java -cp guava-11.0.2.jar测试"未执行,并出现以下错误.有人可以帮我为什么会发生这种情况吗?还是可以 逐步过程 来运行给定代码.谢谢.

"javac -cp guava-11.0.2.jar Test.java" is executing and producing a .class file. However,"java -cp guava-11.0.2.jar Test" is not executing and giving following errors. Can anybody help me why this happening or a step by step procedure to run the given code. Thanks.

错误:

Test.java代码:

Test.java Code:

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;

public class Test {
    public static void main(String[] args) {
        try {
            String key = "hello";
            Multimap myMap = HashMultimap.create();
            myMap.put(key, 1);
            myMap.put(key, 5000);
            System.out.println(myMap.get(key));
        }
        catch (Exception e) {
            System.out.println(e);
        }
    }
}

推荐答案

通过将Guava放在类路径中,您已经替换了当前目录作为类路径.这样做:

By putting Guava on the classpath, you've replaced the current directory as the classpath. Do this:

java -cp guava-11.0.2.jar;. Test

;在Windows上用作路径分隔符(在Unix上为:),而.则用于当前目录.因此,基本上是这样说的:使用Guava jar文件和当前目录的类路径运行,并在名为Test的类中执行main方法"

; is used as the path separator on Windows (it would be : on Unix) and . is for the current directory. So this basically says: "Run with a classpath of the Guava jar file and the currently directory, and execute the main method in the class called Test"

我没有发现您的第二次尝试-问题是使用冒号而不是分号作为路径分隔符.最好使用.;guava-11.0.2.jar代替.

I hadn't spotted your second attempt - the problem with that is the use of a colon instead of a semi-colon as the path separator. It would be fine to use .;guava-11.0.2.jar instead.

这篇关于运行番石榴的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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