且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Mac终端:找不到或加载主类CLASSNAME

更新时间:2022-10-22 17:35:12

首先确保您位于***

之上的目录

如果该类属于 com.foo.bar 你想要在 com 之上的目录中。



在你的情况下,你想要在上面的目录 startPack



然后,您需要使用完全限定名来运行类...

  java statPack.mainClass 

例如...


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

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...