heldopslippers
heldopslippers

Reputation: 840

Java import from other directory

I am building a Enterprise Service Bus (ESB) with Java. I won't get into details But I have to build multiple servers who make use of the same classes.

I have the following directory structure:

/server1
   -Main.java
/server2
    -Main.java
/com
    -Database.java

I want to import from the Main.java class for example the Database.class. But of course the following statements won't work:

import com.Database;

I am working with the javac compiler in the command line (so not eclipse stuff or whatever. just TextMate and the command line). And I found a (pretty stupid) solution by creating a symbolic link in the servers to the com directory. But that is not really an ideal solution.

Does anybody have a better one?

Upvotes: 2

Views: 7727

Answers (2)

heldopslippers
heldopslippers

Reputation: 840

Thanx Joachim. Well if you don't know where to look you won't find the answer on google.. so not able to find the answer by yourself doesn't mean you are a bad programmer.

I found the answer (thanxs to Joachim).

for people reading this:

javac Main.java -cp ../com -cp ./

will do the trick (the last -cp ./ is not necessary but i also have a Controller class that IS located in the same directory and i need to import that one too).

Upvotes: 1

Joachim Sauer
Joachim Sauer

Reputation: 308001

Set up your classpath to include the directory that contains the com directory.

And I hate to be negative, but if you need help with that, then writing an ESB is probably above your current skill level.

Upvotes: 2

Related Questions