How to compile java package structures using javac

前端 未结 5 628
逝去的感伤
逝去的感伤 2020-11-29 06:20

I am trying to compile (from the command line) a java package that imports another package of my own. I was following a tutorial online but it seems that I get an error when

5条回答
  •  猫巷女王i
    2020-11-29 06:34

    The issue was that the class path needs to be set for each command (javac and java):

    Attempted Steps

    1. instead of going to subpackage, compile HelloWorld.java from the top_level:

      $javac -cp . importpackage/subpackage/HelloWorld.java

    2. compile CallPackage.java in the same way:

      $javac -cp . CallPackage.java

    3. run the file using the class path also:

      $java -cp . CallPackage

    NOTE: running "$java CallPackage" will give an error "Error: Could not find or load main class CallPackage"

    In summary, during each step, the class path must be specified. It worked after running it as such.

提交回复
热议问题