OSGI compatibility
See original GitHub issueShaded jar failed to run as an OSGI bundle
We try to run neo4j-java-driver as an OSGI bundle into an OSGI container (felix).
We also provides required dependencies for neo4j driver to works : io.netty
and org.hdrhistogram
as external jars.
When we launch the application, one of our service try to instantiate the neo4j driver into the activate() method by calling GraphDatabase.driver
method.
@Activate
public void activate(Neo4jClientConfig config) {
String host = config.neo4j_host();
int boltPort = config.bolt_port();
String hostHttp = config.neo4j_host();
int portHttp = config.neo4j_port();
String protocolHttp = config.neo4j_protocol();
init(URI.create(protocolHttp + "://" + hostHttp + ":" + portHttp), URI.create("bolt://" + host + ':' + boltPort));
}
public void init(URI httpUri, URI boltUri) {
this.host = new HttpHost(httpUri.getHost(), httpUri.getPort(), httpUri.getScheme());
this.client = new HttpClientBuilder().build();
driver = GraphDatabase.driver(boltUri, Config.build().withoutEncryption().toConfig());
}
We use the neo4j-java-driver:1.6.3
which embeds netty and hdrhistogram dependencies with rewritten package names (shaded jar).
When we use this bundle, the GraphDatabase.driver()
method failed with the following error :
16:30:54.585 [ERROR] o.o.u.l.i.o.LoggerService {FelixStartLevel} - [neo4j-bolt-client(73)] The activate method has thrown an exception
java.lang.NoClassDefFoundError: Could not initialize class org.neo4j.driver.internal.shaded.io.netty.channel.DefaultChannelId
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannel.newId(AbstractChannel.java:111)
at org.neo4j.driver.internal.shaded.io.netty.channel.AbstractChannel.<init>(AbstractChannel.java:83)
at org.neo4j.driver.internal.shaded.io.netty.bootstrap.FailedChannel.<init>(FailedChannel.java:33)
at org.neo4j.driver.internal.shaded.io.netty.bootstrap.AbstractBootstrap.initAndRegister(AbstractBootstrap.java:330)
at org.neo4j.driver.internal.shaded.io.netty.bootstrap.Bootstrap.doResolveAndConnect(Bootstrap.java:163)
at org.neo4j.driver.internal.shaded.io.netty.bootstrap.Bootstrap.connect(Bootstrap.java:145)
at org.neo4j.driver.internal.async.ChannelConnectorImpl.connect(ChannelConnectorImpl.java:78)
at org.neo4j.driver.internal.async.pool.NettyChannelPool.connectChannel(NettyChannelPool.java:64)
at org.neo4j.driver.internal.shaded.io.netty.channel.pool.SimpleChannelPool.acquireHealthyFromPoolOrNew(SimpleChannelPool.java:179)
at org.neo4j.driver.internal.shaded.io.netty.channel.pool.SimpleChannelPool.acquire(SimpleChannelPool.java:164)
at org.neo4j.driver.internal.shaded.io.netty.channel.pool.FixedChannelPool.acquire0(FixedChannelPool.java:266)
at org.neo4j.driver.internal.shaded.io.netty.channel.pool.FixedChannelPool.access$300(FixedChannelPool.java:38)
at org.neo4j.driver.internal.shaded.io.netty.channel.pool.FixedChannelPool$3.run(FixedChannelPool.java:240)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:404)
at org.neo4j.driver.internal.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:886)
at org.neo4j.driver.internal.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Fixing the issue
We successfully fix this issue by deploying the non shaded jar i.e. the original neo4j-driver-java bundle.
Is there any reason why the neo4j-java-driver now embeds these dependencies into the jar (with rewritten packages), it seems to be the case since versions > 1.4.x ?
It seems that packaging a simple jar is the solution for OSGI compatibility anyway.
Thanks for your help
Issue Analytics
- State:
- Created 5 years ago
- Comments:21 (17 by maintainers)
Hi and thanks for the reply. Yes I will provide an example project as soon as I have a moment to package a reproducer project based on osgi (as tiny as possible). I’ll try to find a moment soon.
Driver 1.7.1 containing the given fix is now released.