On 02/27/2015 07:01 AM, Manuel Fink wrote:
Hey everyone,
I am developing a plugin for protege 4.3 in which I need to use Stardog client libraries. I tried almost anything now, from extracting all stardog .jars into my plugin .jar to building an osgi bundle out of the stardog jars in which I am exporting all packages and import all of them with my plugin.
You are asking a question about OSGi class loading. OSGi provides
fine grain control over java package visibility and class loading
but with this power comes some complexity.
There are several ways to get the results that you want. One
approach is to embed the stardog jars in your plugin and another
involves making the stardog jars into an OSGi plugin of its own and
to import the classes that you need. I will assume that you are
trying to do the former. The latter version is better if you expect
that there will be other developers who want to use the stardog jar
files.
I will start by describing the result that you are trying to
achieve. This effect is achieved by several other plugins including
org.protege.editor.owl.jar. This jar file uses classes from two
other jar files (org.protege.xmlcatalog-1.0.4.jar and
protege-owlapi-extensions-3.2.6.jar) that it embeds.
If you look at this jar file (using any tool that understands the
zip format), you can find the evidence of how it works. The
contents of the org.protege.editor.owl.jar file looks like this:
Neptune:plugins% unzip -v org.protege.editor.owl.jar
Archive: org.protege.editor.owl.jar
Length Method Size Cmpr Date Time CRC-32 Name
-------- ------ ------- ---- ---------- ----- -------- ----
29545 Defl:N 4182 86% 02-28-2015 14:29 8321a776 META-INF/MANIFEST.MF
...
50854 Defl:N 43017 15% 02-01-2015 11:42 86a1cf69 org.protege.xmlcatalog-1.0.4.jar
...
94141 Defl:N 84383 10% 02-01-2015 11:42 865de7c6 protege-owlapi-extensions-3.2.6.jar
...
For classes that execute code defined by org.protege.editor.owl.jar,
the classpath to use is defined by the manifest. The relevant
portion of the MANIFEST.MF file involves the Bundle-Classpath. The
first few lines of MANIFEST.MF look like this:
Manifest-Version: 1.0
Bnd-LastModified: 1425162569412
Build-Jdk: 1.8.0_31
Built-By: developer
Bundle-Activator: org.protege.editor.owl.ProtegeOWL
Bundle-ClassPath: .,protege-owlapi-extensions-3.2.6.jar,
org.protege.xmlcatalog-1.0.4.jar
Bundle-Description: OWL ontology editing infrastructure used by the Prot
ege desktop application.
There are several ways to generate and maintain an OSGi manifest.
For small and one time projects, eclipse has nice tools for managing
a manifest. I haven't done this for a long time but my recollection
is that they work very well.
I am a firm believer in using IDE independent build scripts however
and I think that maven is a very good choice. It is used by the
Protege team and it has good support for OSGi. Also there are
stardog jars in maven central which is useful. I found some
tutorials about
http://protegewiki.stanford.edu/wiki/PluginAnatomy (may be out of date)
http://wso2.com/library/tutorials/develop-osgi-bundles-using-maven-bundle-plugin/
http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
Also here is a fragment of the pom.xml file for
org.protege.editor.owl.jar:
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.4.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-Activator>org.protege.editor.owl.ProtegeOWL</Bundle-Activator>
<Bundle-ClassPath>., {maven-dependencies}</Bundle-ClassPath>
<Bundle-SymbolicName>${project.artifactId};singleton:=true</Bundle-SymbolicName>
<Bundle-Vendor>The Protege Development Team</Bundle-Vendor>
<Embed-Dependency>protege-owlapi-extensions, org.protege.xmlcatalog</Embed-Dependency>
<Export-Package>
${project.artifactId}*;version=${project.version},
org.protege.xmlcatalog.*
</Export-Package>
<Import-Package>
org.eclipse.core.runtime;registry=split,
*
</Import-Package>
<Include-Resource>plugin.xml, {maven-resources}</Include-Resource>
</instructions>
</configuration>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>install</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
</plugin>
The problem is I am always getting a stardog exception that is usually caused by missing jar files in the class path. I am using stardog classes which again use other stardog classes from the library than can't be found by the classloader as it seems. When I try to connect to my stardog server the driver class for handling the http address of the server can't be loaded. If I try the same code in an empty eclipse project where I import the same stardog jars it works fine.
Given this description I am wondering if you have given us enough
information. What is the exception exactly? Are you sure that you
are not able to load the relevant stardog classes? It looks like
some of the stardog jars may be class loader aware and sometimes
exceptions that such libraries generate are not obvious.
When you run the code in eclipse, are you running the code as plain
java code or are you running the code as an OSGi bundle? If you are
doing the latter then your problem is simply one of some
configuration files.
-Timothy
Can anyone help me with this?
Thanks in advance,
Manuel
_______________________________________________
protege-dev mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-dev
_______________________________________________
protege-dev mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-dev