Run from command line, Wrong Name error

后端 未结 6 1896
栀梦
栀梦 2020-12-22 07:58

I want to run a Java project from the command line which I start using a batch file, but I get the wrong name error.

The directory setup:

  • srcMVC
      <
6条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-22 08:26

    NoClassDefFoundError in Java comes when Java Virtual Machine is not able to find a particular class at runtime which was available during compile time.

    For example if we have a method call from a class or accessing any static member of a Class and that class is not available during run-time then JVM will throw NoClassDefFoundError.

    By default Java CLASSPATH points to current directory denoted by "." and it will look for any class only in current directory.

    So, You need to add other paths to CLASSPATH at run time. Read more Setting the classpath

    java -cp bin main.Main

    where Main.class contains public static void main(String []arg)

提交回复
热议问题