Struggle with OSGi dependencies for Pellet and OWL-API - java

I wrote a facade for the owl-api paired with the pellet reasoner to easily access an ontology. It worked quiet well. Then I tried to pack it as an OSGi Bundle and use it via an TrackerService from other services. The owl-api bundle needs guava and trove to run. For trove there is no bundle. Even after reloading the target platform, the pellet jars were not recognized as bundle in eclipse (I took them from jpm4j). So I thought about just take all the jar- stuff and squeeze it into the bundle.
I read a lot of how-to's for packaging third-party jars with a bundle. I use the maven-bundle-plugin and after reading some documentation from this plugin and bndtools I decided to use conditional-package, because here it was described that all entries in the pom are passed to the bndtools. After the compilation, no jar was packaged with my bundle :(. Then I used embed-dependencies. It didnt't work because the transient dependiencies were not available at runtime. So I used the embed-transient tag (I already read that this is bad style). The Import-Package part was filled automatically with all transient dependencies, so I overwrote it by hand to ged rid of the errors regarding the unsolved imports. This worked and I was able to use the owl-api to insert new properties,individuals, etc (yeah).
When I tryed to start the pellet reasoner, I got the error message below at runtime. I think it is about the dependency-mess in my project again. I already know that the current way is the wrong one, but I was not able to find a better one. Please help me to get this dependency management in OSGi right.
Cheers,
Stephan
ERROR MESSAGE:
!ENTRY org.apache.felix.configadmin 4 0 2015-11-16 11:28:45.218
!MESSAGE [org.osgi.service.cm.ManagedService, id=28, bundle=7/initial#reference:file:..vdg.iCar.service]: Unexpected problem updating configuration vdg.iCar.service
!STACK 0
java.lang.Error: javax.xml.datatype.DatatypeConfigurationException: Provider for class javax.xml.datatype.DatatypeFactory cannot be found
at javax.xml.bind.DatatypeConverterImpl.<clinit>(DatatypeConverterImpl.java:892)
at javax.xml.bind.DatatypeConverter.initConverter(DatatypeConverter.java:140)
at javax.xml.bind.DatatypeConverter.parseFloat(DatatypeConverter.java:243)
at com.clarkparsia.pellet.datatypes.types.floating.XSDFloat.getValue(XSDFloat.java:81)
at com.clarkparsia.pellet.datatypes.types.floating.XSDFloat.getCanonicalRepresentation(XSDFloat.java:58)
at com.clarkparsia.pellet.datatypes.DatatypeReasonerImpl.getCanonicalRepresentation(DatatypeReasonerImpl.java:365)
at org.mindswap.pellet.ABox.createLiteral(ABox.java:1746)
at org.mindswap.pellet.ABox.addLiteral(ABox.java:1725)
at org.mindswap.pellet.KnowledgeBase.addPropertyValue(KnowledgeBase.java:974)
at com.clarkparsia.pellet.owlapiv3.PelletVisitor.visit(PelletVisitor.java:1103)
at uk.ac.manchester.cs.owl.owlapi.OWLDataPropertyAssertionAxiomImpl.accept(OWLDataPropertyAssertionAxiomImpl.java:119)
at com.clarkparsia.pellet.owlapiv3.PelletVisitor.visit(PelletVisitor.java:699)
at uk.ac.manchester.cs.owl.owlapi.OWLOntologyImpl.accept(OWLOntologyImpl.java:1516)
at com.clarkparsia.pellet.owlapiv3.PelletReasoner.refresh(PelletReasoner.java:967)
at com.clarkparsia.pellet.owlapiv3.PelletReasoner.<init>(PelletReasoner.java:345)
at com.clarkparsia.pellet.owlapiv3.PelletReasoner.<init>(PelletReasoner.java:304)
at com.clarkparsia.pellet.owlapiv3.PelletReasonerFactory.createReasoner(PelletReasonerFactory.java:71)
at de.dlr.vdg.ontology.osgi.impl.util.ReasonerUtil.getInferredOntology(ReasonerUtil.java:56)
at de.dlr.vdg.ontology.osgi.impl.util.ReasonerUtil.getInferredRelations(ReasonerUtil.java:304)
at de.dlr.vdg.ontology.osgi.impl.OntologyServiceImpl.startReasoning(OntologyServiceImpl.java:106)
at de.dlr.vdg.iCar.osgi.impl.iCarServiceImpl.start(iCarServiceImpl.java:67)
at de.dlr.vdg.iCar.osgi.Activator.updated(Activator.java:65)
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updated(ManagedServiceTracker.java:189)
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.updateService(ManagedServiceTracker.java:152)
at org.apache.felix.cm.impl.helper.ManagedServiceTracker.provideConfiguration(ManagedServiceTracker.java:85)
at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.provide(ConfigurationManager.java:1444)
at org.apache.felix.cm.impl.ConfigurationManager$ManagedServiceUpdate.run(ConfigurationManager.java:1400)
at org.apache.felix.cm.impl.UpdateThread.run(UpdateThread.java:103)
at java.lang.Thread.run(Thread.java:745)
Caused by: javax.xml.datatype.DatatypeConfigurationException: Provider for class javax.xml.datatype.DatatypeFactory cannot be found
at javax.xml.datatype.FactoryFinder.findServiceProvider(FactoryFinder.java:304)
at javax.xml.datatype.FactoryFinder.find(FactoryFinder.java:268)
at javax.xml.datatype.DatatypeFactory.newInstance(DatatypeFactory.java:145)
at javax.xml.bind.DatatypeConverterImpl.<clinit>(DatatypeConverterImpl.java:890)
... 28 more
Caused by: java.util.ServiceConfigurationError: javax.xml.datatype.DatatypeFactory: Provider org.apache.xerces.jaxp.datatype.DatatypeFactoryImpl not a subtype
at java.util.ServiceLoader.fail(ServiceLoader.java:239)
at java.util.ServiceLoader.access$300(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:376)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at javax.xml.datatype.FactoryFinder$1.run(FactoryFinder.java:297)
at java.security.AccessController.doPrivileged(Native Method)
at javax.xml.datatype.FactoryFinder.findServiceProvider(FactoryFinder.java:292)
... 31 more
POM-File (important parts):
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>3.0.1</version>
<extensions>true</extensions>
<configuration>
<manifestLocation>META-INF</manifestLocation>
<instructions>
<Private-Package>${bundle.namespace}.*</Private-Package>
<Export-Package>${bundle.namespaceShared}</Export-Package>
<Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
<Bundle-Activator>${bundle.namespace}.Activator</Bundle-Activator>
<Bundle-RequiredExecutionEnvironment>JavaSE-1.8</Bundle-RequiredExecutionEnvironment>
<Embed-Dependency>*;scope=compile|runtime</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Import-Package>org.osgi.framework;version="[1.6,2)",org.osgi.se
rvice.cm;version="[1.4,2)",org.slf4j;version="[1.7,2)"</Import-Package>
<Bundle-ClassPath>.,{maven-dependencies}</Bundle-ClassPath>
</instructions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
<version>4.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
<version>4.3.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.owlapi</groupId>
<artifactId>owlapi-distribution</artifactId>
<version>3.5.2</version>
<type>bundle</type>
</dependency>
<dependency>
<groupId>com.github.ansell.pellet</groupId>
<artifactId>pellet-owlapiv3</artifactId>
<version>2.3.6-ansell</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.github.ansell.pellet</groupId>
<artifactId>pellet-query</artifactId>
<version>2.3.6-ansell</version>
<type>jar</type>
</dependency>
</dependencies>

After an additional day of research I came across this thread at oracle.
The pellet-api references the xerces and xml-api libs and due to the transient inclusion of dependencies, these libs were included in my bundle. But these libs are already present in the java runtime environment. Therefore I excluded them in the Embed-Dependency section and everything works.
<Embed-Dependency>*;scope=compile|runtime;inline=false;groupId=!xml-apis|xerces</Embed-Dependency>

Related

Failed to load api definition when loading files from application properties

I have an openapi file generated through restdocs and converted into this format. They are added to the resources folder, and the properties file is pointing to their format, however, swagger is failing to load and I'm not sure what else I could be missing.
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<version>${spring-restdocs-mockmvc.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${springdoc-openapi-ui.version}</version>
</dependency>
<dependency>
<groupId>capital.scalable</groupId>
<artifactId>spring-auto-restdocs-core</artifactId>
<version>${spring-auto-restdocs-core.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.epages</groupId>
<artifactId>restdocs-api-spec</artifactId>
<version>${restdocs-api-spec.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.epages</groupId>
<artifactId>restdocs-api-spec-mockmvc</artifactId>
<version>${restdocs-api-spec.version}</version>
<scope>test</scope>
</dependency>
<plugin>
<groupId>io.github.berkleytechnologyservices</groupId>
<artifactId>restdocs-spec-maven-plugin</artifactId>
<version>${restdocs-spec.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<!--suppress MavenModelInspection -->
<skip>${skipTests}</skip>
<host>localhost:8081</host>
<specification>OPENAPI_V3</specification>
<outputDirectory>${project.build.directory}/classes/static/docs</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Thank you very much.
A related question was posted here and this answer solved the issue: https://stackoverflow.com/a/75273492/6654475
In summary, it was related to this line that needed to be removed spring.web.resources.add-mappings=false and the yml file that needed to be moved to the resources/static/ folder.

Maven JavaDoc Plugin Failing to parse XML

I have trying to generate Javadoc using the maven-javadoc-plugin and a custom doclet. I am using JDK 11 and I have implemented the methods of the Doclet interface. However, in one of the methods, I am trying to unmarshal an XML file. I am receiving the following error:
javax.xml.bind.JAXBException: Implementation of JAXB-API has not been
found on module path or classpath.
I have configured the javadoc-plugin as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<doclint>none</doclint>
<useStandardDocletOptions>false</useStandardDocletOptions>
<outputDirectory>my.output.directory</outputDirectory>
<doclet>my.doclet/doclet>
<docletArtifact>
<groupId>my.group.id</groupId>
<artifactId>myartifact</artifactId>
<version>my.project.version</version>
</docletArtifact>
<show>private</show>
</configuration>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</plugin>
What should I do to solve this issue?

Execute class in submodule during maven build

I have a multimodule maven project and I like to execute a java class during the build of the multimodule.
The Java class is part of a submodule, so I tried to add the exec-maven-plugin, but it always fail with a ClassNotFoundException
The part looks like
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<id>build-dump</id>
<phase>process-classes</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includePluginDependencies>true</includePluginDependencies>
<mainClass>org.sonar.plugins.coffeelint2java.Coffeelint2Java</mainClass>
<arguments>
<argument>${rules.path}</argument>
</arguments>
</configuration>
</plugin>
This results in
Caused by: java.lang.NoClassDefFoundError: org/sonar/check/Priority
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.getPriority(CheckTemplateWriter.java:126)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.checkLevelLine(CheckTemplateWriter.java:107)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.lambda$generateReplacementMapping$3(CheckTemplateWriter.java:86)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter$$Lambda$5/161691919.accept(Unknown Source)
at java.util.ArrayList.forEach(ArrayList.java:1249)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.generateReplacementMapping(CheckTemplateWriter.java:84)
at org.sonar.plugins.coffeelint2java.CheckTemplateWriter.generate(CheckTemplateWriter.java:52)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.doGenerateChecks(Coffeelint2Java.java:72)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.generateChecks(Coffeelint2Java.java:59)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.lambda$generateChecks$1(Coffeelint2Java.java:51)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java$$Lambda$4/1333998550.accept(Unknown Source)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.generateChecks(Coffeelint2Java.java:51)
at org.sonar.plugins.coffeelint2java.Coffeelint2Java.main(Coffeelint2Java.java:41)
... 6 more
The sonar dependency is defined in the parent pom, but also when I add it to the <dependency> section in the submodule pom, it returns the same result.
How do I need to define the pom correctly, to include the dependencies when executing the main class ?
=== UPDATE ===
The dependency in the parent pom is
<dependencies>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>19.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.sonar</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>5.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.sslr-squid-bridge</groupId>
<artifactId>sslr-squid-bridge</artifactId>
<version>2.6.1</version>
</dependency>
</dependencies>
The submodule itself also adds other dependencies
<dependencies>
<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
<version>1.48</version>
</dependency>
</dependencies>
And right after updating my question and adding the dependency information to it, I saw it myself.
the provided attribute was the problem. argh
removing it solved the problem

Jackson ObjectMapper giving me a VerifyError only when compiled/packaged with Maven

I'm a relatively new Java programmer, and I've only worked with Maven and Jackson on a couple projects.
In my current project, I am attempting to build a process I can run on Heroku (which I'm brand new to) once every 24 hours. Part of this program uses Jackson to deserialize json to use in an array. When run through my IDE (IntelliJ), everything works fine. However, when I run the program after a mvn package I get the following error:
Exception in thread "main" java.lang.VerifyError:
(class: org/codehaus/jackson/map/ObjectMapper, method: <init> signature: (Lorg/codehaus/jackson/JsonFactory;Lorg/codehaus/jackson/map/SerializerProvider;Lorg/codehaus/jackson/map/DeserializerProvider;Lorg/codehaus/jackson/map/SerializationConfig;Lorg/codehaus/jackson/map/DeserializationConfig;)V) Bad type in putfield/putstatic
at com.example.project.Main.main(Main.java:47)
This is obviously a showstopper since it keeps me from deploying to Heroku.
The line throwing the error is when I initialize an ObjectMapper:
ObjectMapper mapper = new ObjectMapper();
As for my POM, I was following this tutorial from Heroku. Here are the relevant sections from my POM:
...
<build>
<sourceDirectory>src/main/java</sourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>1.1.1</version>
<configuration>
<assembleDirectory>target</assembleDirectory>
<programs><program>
<mainClass>com.example.project.Main</mainClass>
<name>main</name>
</program></programs>
</configuration>
<executions>
<execution>
<phase>package</phase><goals><goal>assemble</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals><goal>copy-dependencies</goal></goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mrbean</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-asl</artifactId>
<version>0.9.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.13</version>
</dependency>
...
</dependencies>
...
So my process is a mvn clean install and a mvn package (where both succeed), and then sh target/bin/main (where we get the error).
If I can provide any more useful information, please let me know! Thanks in advance!
EDIT:
After running my program differently...
java -cp target/classes:"target/dependency/*" com.example.project.Main
I found that I essentially ran into the same problem as #Jithin from this post:
Jackson + Tomcat - java.lang.VerifyError: Cannot inherit from final class
The error was coming from having conflicting Jackson versions in my classpath/dependency tree (i.e., one of my other dependencies was also using Jackson). I found that, in my case, the only Jackson dependency I required was jackson-annotations. The program now runs like a charm! Hopefully this helps someone down the road.

Using JDO Persistent classes from a separate module with datanucleus maven plugin

I have a working application that persists to a database using JDO - I want to use a PersistenceCapable class that's in a second java module. Although the app compiles a simple test gives the error:
The class "com.hello.world.Foo" is not persistable This means that it either hasnt been enhanced, or that the enhanced version of the file is not in the CLASSPATH (or is hidden by an unenhanced version), or the Meta-Data/annotations for the class are not found.
Ok, so the enhancer plugin is not running on the classes in the second module. I'm not sure what i need to do to point the enhancer at that module during the build.
ParentProject
Second Module: com.hello.world.Foo
ParentProject pom.xml with relevant parts - problem is how do i point the enhancer at the second module containing my persistent class?
<dependencies>
<dependency>
<groupId>Second Module</groupId>
<artifactId>Second Module</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>javax.jdo</groupId>
<artifactId>jdo-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>[3.2.0, 3.2.99)</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-api-jdo</artifactId>
<version>[3.2.0, 3.2.99)</version>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-rdbms</artifactId>
<version>[3.2.0, 3.2.99)</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-maven-plugin</artifactId>
<version>3.3.0-release</version>
<configuration>
<api>JDO</api>
<props>${basedir}/datanucleus.properties</props>
<log4jConfiguration>${basedir}/log4j.properties</log4jConfiguration>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>enhance</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
got it - i had to add the exact same pom.xml config in the question to the second module and do a mvn install to get those classes enahnced before compiling the parent module. Working on both Jetty and GAE. I thought, wrongly, that the parent module would enhance classes included in the module dependencies.
Thanks for your help DataNucleus!

Categories