Sabri Özgür
Sabri Özgür

Reputation: 672

If a class calls another, can I put them in separate JAR files?

Let's say I have two classes Airport and Airplane:

public class Airport
{
    public static void main(String args[])
    {
        Airplane a1 = new Airplane();
    }
}

public class Airplane
{
    int seats;
    public Airplane()
    {
        seats = 10;
    }
}

I want to put these classes in separate JAR files so that I can develop them independent of each other in future in case any issue comes up. Since Airport calls Airplane I have to import Airplane in the Airport source file. I was thinking of importing them in the project that I will use to call these classes. But even if I import both of them in project, there still are issues about resolves.

UPDATE: Can you give an example .classpath to accomplish this call hierarchy? I simply added JARs to the .classpath of Main Project but Airport complains that it can't find methods of Airplane.

Call Tree of what I want to accomplish

Upvotes: 1

Views: 62

Answers (1)

lexicore
lexicore

Reputation: 43651

Yes, you can import Airplane into Airport even if these classes are in different JARs. However, both JARs must be present in the classpath.

Upvotes: 6

Related Questions