I am writing a Java application that will load third party “drivers”. I intend to develop an interface that will define the required methods that the “driver” must implement in order to work within the application.
The intent is for the “driver” to be contained within a jar file. Then third party “driver” developers will be required to implement the interface.
As I’m trying to figure this out, I moved the “driver” code to a jar and found that I am having trouble since I have the interface defined in both the main application and in the jar file.
Is there a recommended way to implement this approach, or am I headed the wrong way?
j
You basically define the interface once, e.g. in an API jar. This jar is then used by the main application as well as the driver.
The driver library would then have this API jar as a dependency that is provided by the main application.
In terms of Maven the dependency would have scope
providedorcompilefor the library.Note that you should avoid having the same class twice in different libraries since those will most likely lead to class loading problems, class cast exceptions etc. (unless there’s some class loader scoping that isolates applications, like most application servers do).