I am trying to import OWL-Api into a jar-packaged project. This library has many dependencies, which it provides in one OSGi bundle.
As I do not wish to maintain a list of dependencies of dependencies manually, I would like to use that bundle; as each dependency is packed as a jar inside the jar, just specifying it in the manifest does not work.
According to the OWL-Api mailing list, the easiest way is therefore to use this jar as an OSGi bundle and to turn the project into one as well.
Sadly, the latter is not an option. The existence of an independent OSGi loader may not be assumed as a requirement.
I have therefore (successfully?) attempted to embed the Equinox loader into my program and install the bundle on runtime. (Note: I picked Equinox at random. If another loader would be better suited for the task, say the word.)
... And now I have no idea how to proceed. The dependencies are not automatically loaded. How would I load them in a way that needs not listing them one by one?
To elaborate: If at any time in the future, the dependencies of OWL-Api change, be it through addition or removal, this shall not result in a need to adjust the code of the project. Only changes to the direct, first generation dependency on OWL-Api itself may.
Furthermore, if a different technique would be easier to attain the same goal (still using the provided bundle), I am interested to read of it.
Error message (same as without Equinox):
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/inject/Provider
[...]
Caused by: java.lang.ClassNotFoundException: com.google.inject.Provider
[...]
The corresponding class file is present at lib/owlapi-osgidistribution-4.1.0.jar/lib/guice-4.0.jar/com/google/inject/Provider.class .
Test project file:
import org.eclipse.core.runtime.adaptor.EclipseStarter;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.OWLOntologyManager;
class Main
{
public static void printThrowable(Throwable e)
{
do
{
System.err.println("Equinox initialisation failed:");
System.err.println(e.getMessage());
System.err.println("");
e = e.getCause();
}
while(e != null);
}
public static void main(String[] args)
{
String[] equinoxArgs = { "-configuration ./config.ini" };
try{ EclipseStarter.startup(equinoxArgs, null); }
catch(Throwable e)
{
printThrowable(e);
System.exit(1);
}
OWLOntologyManager m = OWLManager.createOWLOntologyManager();
try{ EclipseStarter.shutdown(); }
catch(Throwable e){ printThrowable(e); }
System.out.println("Hallo Welt.");
}
}
The output is displayed when the call to OWLManager is commented out, so Equinox seems to start up and shut down just fine.
Folder structure:
./
lib/
org.eclipse.osgi_3.10.2.v20150203-1939.jar
owlapi-distribution-4.1.0.jar
owlapi-osgidistribution-4.1.0.jar <- OSGi bundle
lib/
<...>.jar <- OWL-Api dependencies
config.ini <- Equinox configuration file
Main.jar <- project executable
Manifest:
Class-Path: ./lib/owlapi-distribution-4.1.0.jar ./lib/org.eclipse.osgi_3.10.2.v20150203-1939.jar
Main-Class: Main
Configuration file:
eclipse.ignoreApp=true
osgi.bundles=owlapi-osgidistribution-4.1.0.jar@start
osgi.noShutdown=true