unj2
unj2

Reputation: 53481

How can I compile my Java class depending on another class and a some libraries?

My structure looks like this

\Project1 
  \src
    \pkg1
      Main.java
    \pkg2
      Auxillary.java
  \Destination
    \class
    \lib

I need to compile Main.java which has dependencies in Auxillary.java and jars in \lib into \Destination\class

I am in the Project1 directory.

I tried

javac -cp Destination\lib\*;src\pkg2\* -d Destination\class

However, I get a package not found for Auxillary.java.

What am I doing wrong?

Upvotes: 0

Views: 231

Answers (2)

Nike
Nike

Reputation: 312

You can use ant script to make these steps simpler. Try once!

Upvotes: 0

Jon Skeet
Jon Skeet

Reputation: 1499860

A classpath entry can't refer to a source directory. Try this:

javac -Djava.ext.dirs=Destination\lib -d Destination\class
      src\pkg1\Main.java src\pkg2\Auxiliary.java

i.e. compile all the source code in one go. Alternatively:

javac -Djava.ext.dirs=Destination\lib -d Destination\class
      src\pkg2\Auxiliary.java

javac -Djava.ext.dirs=Destination\lib -cp Destination\class
      -d Destination\class src\pkg1\Main.java

That will compile Auxiliary.java first, and then use its destination directory as part of the classpath when compiling Main.java.

Upvotes: 2

Related Questions