question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OSGI compatibility

See original GitHub issue

Shaded 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:closed
  • Created 5 years ago
  • Comments:21 (17 by maintainers)

github_iconTop GitHub Comments

1reaction
agjinicommented, Oct 25, 2018

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.

0reactions
lutovichcommented, Nov 23, 2018

Driver 1.7.1 containing the given fix is now released.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create OSGi compatible components | Integrations | Flow
If you want to create an OSGi compatible component in a separate bundle then you should be aware about several aspects: * Making...
Read more >
OSGi Semantic Versioning - Background
Backward compatibility decouples the importer and exporter by allowing a range of exporters to satisfy the needs of an importer. This allows an...
Read more >
Knopflerfish OSGi & Java Compatibility Guide
A compatibility guide for the different versions of KF, Java and OSGi.
Read more >
Unraveling Java and OSGi class loader problems
Boot compatibility instructs the Equinox framework to perform a last gasp delegation to the boot class loader. If the class is not found...
Read more >
OSGi - Wikipedia
OSGi is an open specification and open source project under the Eclipse Foundation. ... to locate a parser with desired properties and compatibility...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found