LoginSignup
11
8

More than 5 years have passed since last update.

javaのクラス実行を別ディレクトリからする時のオプション

Posted at

現在のディレクトリにhello.classがあるときは

$ java hello
Hello World!

でいけるけど、
一個前のディレクトリにある時に

$ java ../hello

ってすると

エラー: メイン・クラス...helloが見つからなかったかロードできませんでした

ってなる。
2分ハマってヘルプ見て解決

    -classpath <ディレクトリおよびzip/jarファイルのクラス検索パス>
                  クラス・ファイルを検索するディレクトリ、
                  JARアーカイブおよびZIPアーカイブの:で区切られたリストです。

これや!

$ java -classpath ../ hello
Hello World!

Qiitaに書くのが楽しい時期です。

11
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
8