In case it helps others, I found that the reason for the ClassNotFound error is
that derby.jar and derbyclient.jar split packages (org.apache.derby.jdbc).
So I solved the issue by:
1- Start Derby from the POM before integration test:
<plugin>
<groupId>org.carlspring.maven</groupId>
<artifactId>derby-maven-plugin</artifactId>
<executions>
<execution>
<id>start-derby</id>
<phase>integration-test</phase>
<goals>
<goal>start</goal>
</goals>
<configuration>
<port>1527</port>
</configuration>
</execution>
</executions>
</plugin>
2- Deploy derbyclient jar from my integration test:
mavenBundle()
.groupId("org.apache.derby")
.artifactId("derbyclient”)
.versionAsInProject()
3- Configure Pax-Exam probe bundle to resolve derbyclient packages first:
@ProbeBuilder
public TestProbeBuilder probeConfiguration(TestProbeBuilder probe) {
probe.setHeader(Constants.BUNDLE_SYMBOLICNAME,
"IT-FlinkJDBC-Probe");
probe.setHeader(Constants.DYNAMICIMPORT_PACKAGE,
"org.apache.derby.jdbc;bundle-symbolic-name=derbyclient,org.apache.felix.service.*;status=provisional,*");
return probe;
}
With this, I can load the derby client driver and connect to the external Derby
database:
Class.forName("org.apache.derby.jdbc.ClientDriver”);
even though both derby.jar and derbyclient.jar are deployed, my integration
test only resolves the classes from derbyclient.jar.
> On Jun 14, 2018, at 4:09 PM, Alex Soto <[email protected]> wrote:
>
> Hi,
>
> I want to start a Derby Network Embedded Database as part of my PAX-EXAM
> integration test with Karaf (4.2.0). No matter what I do, I am always
> getting this class not found error:
>
> java.lang.ClassNotFoundException:
> org.apache.derby.iapi.services.property.PropertyUtil not found by
> wrap_file__Users_asoto_.m2_repository_org_apache_derby_derbynet_10.13.1.1_derbynet-10.13.1.1.jar_overwrite_full
> [199]
>
> I am deploying all bundles I think I need:
>
> wrappedBundle(mavenBundle()
> .groupId("org.apache.derby")
> .artifactId("derby")
> .versionAsInProject().getURL() + "$overwrite=full"),
> wrappedBundle(mavenBundle()
> .groupId("org.apache.derby")
> .artifactId("derbyclient")
> .versionAsInProject().getURL() + "$overwrite=full"),
> wrappedBundle(mavenBundle()
> .groupId("org.apache.derby")
> .artifactId("derbynet")
> .versionAsInProject().getURL() + "$overwrite=full"),
> wrappedBundle(mavenBundle()
> .groupId("org.apache.derby")
> .artifactId("derbytools")
> .versionAsInProject().getURL() + "$overwrite=full"),
>
>
> Notice I am wrapping all the jars and overriding their manifests to force
> export-everything, just as a precaution. I may not need to do this, but
> since it was not working, I am forcing it. The error comes from this line of
> code:
>
> NetworkServerControl server = new
> NetworkServerControl(InetAddress.getByName("localhost"), 1527);
>
>
> Karaf starts, normally, i.e., there are no unresolved bundle errors. Inspect
> the Karaf directory created by PAX-EXAM, I see the under the data/tmp the
> various derby jars. The derby.jar is exporting everything including the
> package in question:
>
> org.apache.derby.iapi.services.property;uses:="org.apache.derby.iapi.error,org.apache.derby.iapi.services.daemon,org.apache.derby.iapi.store.access"
>
>
> On the other hand, the derbynet.jar has the Import-Package with the
> aforementioned package:
>
> org.apache.derby.iapi.services.property;resolution:=optional,org.apache.derby.iapi.services.stream;resolution:=optional
>
> If I run Karaf interactively from the directory created by PAX-EXAM, I can
> see all the bundles are deployed, and I can find the class in question:
>
> karaf@root()> bundle:find-class
> org.apache.derby.iapi.services.property.PropertyUtil
> Apache Derby 10.13 (197)
> org/apache/derby/iapi/services/property/PropertyUtil.class
>
>
> I’ve checked everything I can think of. What am I missing? What could be
> causing this?
>
> Best regards,
> Alex soto
>
>
>
>