无法编译和运行Java控制台应用程序OS X终端

时间:2015-03-26 17:24:29

标签: java eclipse macos terminal javac

无法编译或运行我在Eclipse中创建的Hangman控制台应用程序。它位于我的Mac上的~/Documents文件夹中,名为hangman。它没有看到我创建的两个类GamePrompter。我尝试使用-cp,但我不确定我做得对。它不是我尝试过的方式。有什么帮助吗?

HoltnetMacbookAir:hangman godmanliving$ javac -classpath . Hangman.java
Hangman.java:20: error: cannot find symbol
    Game game = new Game(args[0]);
    ^
symbol:   class Game
location: class Hangman
Hangman.java:20: error: cannot find symbol
    Game game = new Game(args[0]);
                    ^
symbol:   class Game
location: class Hangman
Hangman.java:21: error: cannot find symbol
    Prompter prompter = new Prompter(game);
    ^
symbol:   class Prompter
location: class Hangman
Hangman.java:21: error: cannot find symbol
    Prompter prompter = new Prompter(game);
                            ^
symbol:   class Prompter
location: class Hangman
4 errors

1 个答案:

答案 0 :(得分:1)

您需要指定所有需要编译的文件。

看起来在你的情况下会是这样的:

javac -classpath . Hangman.java Game.java Prompter.java

参考文献:

how to compile multiple java source files in command line

http://www.codejava.net/java-core/tools/using-javac-command