Running Java Program from Command Line Linux

前端 未结 4 1976
無奈伤痛
無奈伤痛 2020-12-08 08:24

I am not very experience with java and this is driving me crazy. I wrote a java program FileManagement and I need to run it from the command line.

I can

4条回答
  •  感情败类
    2020-12-08 08:38

    Guys let's understand the syntax of it.

    1. If class file is present in the Current Dir.

      java -cp . fileName

    2. If class file is present within the Dir. Go to the Parent Dir and enter below cmd.

      java -cp . dir1.dir2.dir3.fileName

    3. If there is a dependency on external jars then,

      java -cp .:./jarName1:./jarName2 fileName

      Hope this helps.

提交回复
热议问题