Search code examples
javaclassterminaljavac

Tell javac to read class/interface dependency from classfile


I'm experimenting with java to see if I can build a plugin system into my application. The one rule I want the plugins to adhere to is that they need to implement interface Cake. My directory is:

Projectfolder
   bin
      Foo.class
      Cake.class
   src
      Foo.java
      Bar.java
      Cake.java

Cake.java and Foo.java is in package test.package and Bar.java is in lets say plugin.stuff package (since I don't control this it could of course be anything). Foo.java and Cake.java compiles to JBC (JavaByteCode) without a problem.

Since I don't want to ship my application code to everyone interested in creating a plugin I want to read the information about the interface Cake (which is implemented in Bar.java) from it's .class file. Is this possible? What javac commands is needed to tell javac to take dependency Cake from Cake.class?

To clarify I want to be able to go from:

Foo.class
Cake.class
Bar.java

to:

Foo.class
Cake.class
Bar.class

Solution

  • Okay I found the error or at least I got it working. Since the file Foo.class and Cake.class wasn't placed in folder src/test/package/ the classes/interfaces was not found.

    When I created this hierarchy:

    Projectfolder
       bin
          test
             package
                Foo.class
                Cake.class
       src
          Bar.java
    

    and in the bin folder ran the command javac ..\src\Bar.java then the command ran fine and Bar.class file was generated in the src folder next to the Bar.java file.