0

Here is the scenario
Let say I have a class A.java which is dependent on class B.java.

public Class A{
  public B b=new B();
}
public Class B{
  //Some business logic...
}

And there is application X which uses only class A(somewhere inside X there is new A() ). So
1) can I create 2 jars, one which contain A.class and another jar which contain B.class, add these 2 jars in application ?
2) can I create a one jar which contain only A.class add that jar in application and provide B.class to application on run-time (lets assuming, its possible to inject B.class on runtime)
Note:Adding these 2 classes in single jar is not an option

so as I understand,Class A is compile time dependency of application X and Class B is runtime dependency, correct ?

In point 1 and 2, When I am saying "add jar in application", what exactly I am doing, am I adding those jar in buildpath or classpath of application X ? probably someone can help me in understanding the difference between these "paths", I always gets confused.

Monk789
  • 183
  • 1
  • 10

1 Answers1

0

Basically, you need to first compile, on your project's buildpath, then provide those classes again on the classpath at runtime. You can have the classes together, put them into different jars, and then reunite them at runtime on the classpath.

nanofarad
  • 40,330
  • 4
  • 86
  • 117
  • Can you elaborate "you need to first compile, on your project's buildpath" – Monk789 Oct 16 '13 at 06:10
  • @Monk789 The buildpath is the set of jars needed at compile time. You provide a set of compiled and uncompiled classes/interfaces/enums and obtain a set of compiled jars and class files. These compiled files go their separate ways but must reuinite again when running the application, even if `A` and `B` are in different jars, as long as they are on the runtime classparg. – nanofarad Oct 16 '13 at 10:15