Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to run a java program through the Terminal on Mac, yet getting:

Error: Could not find or load main class (MY CLASSNAME)

I compiled this application with Eclipse, and when I run this with Eclipse, it works fine. Furthermore, I am in the right directory, as when I type "ls" in the Terminal, it lists all the files, includes the class file I am trying to run.

This is what I type:

java mainClass

I would very much appreciate help to solve this!

Thank you,

Dean

EDIT: Solution - instead of java mainClass, it must have package too: java startPackage.mainClass

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
204 views
Welcome To Ask or Share your Answers For Others

1 Answer

Start by making sure you are at the directory above the top level package

If the class belongs to the package com.foo.bar, you want to be in the directory above com.

In your case, you want to be in the directory above startPack.

Then you need to use the fully qualified name to run the class...

java statPack.mainClass

For example...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...