How to run a .class file that is part of a package from cmd?

后端 未结 12 1218
梦如初夏
梦如初夏 2020-12-01 07:11

I keep getting errors when I make my .class part of a package and try to run it from cmd.

Here\'s the code that works after using jav

12条回答
  •  旧巷少年郎
    2020-12-01 08:01

    You do not need a -cp flag while running a java class , -cp needed while running a class or a main program from a binary (jar) file. While running a main program from a command line you need to make sure you have the class in the same folder structure as package name in the java file, ex.

    home/user/foo java com.test.className   
    
    here classNmae class file and exist under home/user/foo/com/test
    

    hope it helps.

提交回复
热议问题