Trouble in compiling classes with dependency

59 views Asked by At

Under the root directory, there are two directories named src and classes.

I have two java files named Master and Slave.

Slave file is under the directory src/com/example/web and compiled master file is under the directory classes/com/example/model.

I have compiled the master class is used. In Slave.java, Master class is used with the help of

import com.example.model.Master

But while compiling in the root directory using

javac -classpath classes -d classes src\com\example\web\Slave.java

the following error is thrown:

package com.example.model does not exist

1

There are 1 answers

1
reza ganji On

if you know the Hierarchy of dependeny , you should build all classes based on dependency. in this case yous should execute this commands sequential :

first

javac -classpath classes -d classes src\com\example\model\Master

then

javac -classpath classes -d classes src\com\example\web\Slave.java

if you have more than a class in packages you can build all with wild cards. for example:

javac -classpath classes -d classes src\com\example\model\*.java