Program-Me-Rev
Program-Me-Rev

Reputation: 6624

How to access a class in another project at runtime

I have a project (called ExtensibleApp). I'm trying to make it modular. The modules will be dependent on some common classes already in ExtensibleApp.

Say I have a module myModule, that extends ExtensibleApp, and is dependent on a Class CommonClass.class, how can I go about importing CommonClass.class into myModule project, and get access to the members.

class MyModuleClass {
    CommonClass commonClass = new CommonClass();

    private void someMethod() {
        commonClass.method....()
    }
}

What I'm trying to do is to create a project that is extensible via modules. These modules will be loaded/ downloaded into a folder outside the ExtensibleApp classpath. At run time how can I go about linking the two Jars together so that they can share classes.

Sample directory structure:

main dir/---ExtensibleApp.jar
        /---plugins ---/myModule.jar
                       /chat.jar
                       /videoplayer.jar
                       /like.jar
                       /unlike.jar
                       /etc.jar
                       /etc_etc.jar

Upvotes: 1

Views: 90

Answers (1)

Sanjeev Kumar
Sanjeev Kumar

Reputation: 660

There are many frameworks available to achieve this. Following is the list of some of these

  • Maven
  • OSGi, if you want finer access control between modules.
  • Ant
  • Apache Ivy
  • Gradle

I've used Maven, OSGi and Ant on eclipse IDE. Out of these I found Maven the easiest and OSGi most useful.

Upvotes: 1

Related Questions