And now I wonder. They say that myApp is a root directory of the package myApp.utils. But why? Why "ws" is not the root directory of the package ws.myApp.utils and the same with "test". Could someone please clarify this for me?
Hi Jan,
ws is not the root directory of ws.myApp.utils because that package doesn't exists. The example is only declaring the package
myApp.utils (line 8 of the code). Then, to successfully locating classes in it you should be located at the directory in which myApp is
directly accesible. The only place where this can happen is in directory ws.
Remember packages "reflect" a directory structure used to organize java classes. So if you code a class named Dates and declare it belongs to myApp.utils package what you're saying to the jvm is that the .class wil be located in a directory called utils that is inside a directory called myApp. So it's your responsibility to make that directories accesible to the jvm. So, the only ways to correctly load the Dates class are:
Inside out of directory test:
java -cp .\test\ws myApp.utils.Dates
Inside directory test:
java -cp .\ws myApp.utils.Dates
Inside directory ws:
java myApp.utils.Dates
Note that, inside directory myApp, if you try:
java myApp.utils.Dates
or
java utils.Dates
An error will be thrown... since myApp directory is not accesible in the first case and there is no class Dates defined to belong to a package named
utils in the second case.
Hope I clarify your doubts.