使用命令行JAVAC编译Java [英] Compiling Java using command line JAVAC

查看:86
本文介绍了使用命令行JAVAC编译Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对使用cmd line javac进行编译有点新,我在编译这个简单的Base-Interface类时遇到了麻烦

I'm kinda new to compiling using cmd line javac and I'm having trouble compiling this simple Base-Interface class

package com.apress.prospring2.ch03.di;

/**
 * @author janm
 */
public interface Encyclopedia {

    Long findLong(String entry);

}







package com.apress.prospring2.ch03.di;

import java.util.Map;
import java.util.HashMap;

/**
 * @author janm
 */
public class HardcodedEncyclopedia implements Encyclopedia {
    private Map<String, Long> entryValues = new HashMap<String, Long>();

    public HardcodedEncyclopedia() {
        this.entryValues.put("AgeOfUniverse", 13700000000L);
        this.entryValues.put("ConstantOfLife", 326190476L);
    }

    public Long findLong(String entry) {
        return this.entryValues.get(entry);
    }
}

我可以使用javac Encyclopedia.java轻松编译Encyclopedia当我尝试编译HardcodedEncyclopedia .java时我得到了

I can easily compile Encyclopedia using javac Encyclopedia.java but when I try to compile HardcodedEncyclopedia .java I get

HardcodedEncyclopedia.java:9: cannot find symbol
symbol: class Encyclopedia
public class HardcodedEncyclopedia implements Encyclopedia {
                                              ^
1 error

有人可以告诉我如何在不使用Ant或Maven的情况下解决这个问题吗?谢谢:)

Can someone please tell me how to solve this without using Ant or Maven? Thanks :)

推荐答案

你需要从包的顶层编译你的类,所以在这种情况下,你需要在com所在的目录中。

You need to compile you classes from the top level of your packages, so in this case, you need to be in the directory where the "com" sits.

然后你可以进行编译:

javac -cp . com/apress/prospring2/ch03/di/*.java

这篇关于使用命令行JAVAC编译Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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