<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: NoClassDefFoundError custom controller using external jars in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-custom-controller-using-external-jars/m-p/302313#M221072</link>
    <description>&lt;P&gt;An update since I managed to solve the issue. I followed the advice given in this StackOverflow post&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them" target="_blank"&gt;https://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them&lt;/A&gt;&amp;nbsp;by creating a static in-project repository so that maven can have better access to the jars. It seemed to do the trick.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Sep 2020 13:35:51 GMT</pubDate>
    <dc:creator>Constan</dc:creator>
    <dc:date>2020-09-03T13:35:51Z</dc:date>
    <item>
      <title>NoClassDefFoundError custom controller using external jars</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-custom-controller-using-external-jars/m-p/302183#M221019</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am running into a problem with deploying a custom controller service to NiFi (I am using the latest version of NIfi 1.12 as of writing this). Now what I am trying to do is to create a custom controller service that would allow me to access a Virtuoso DB instance (similarly to&amp;nbsp;&lt;STRONG&gt;DBCPConnectionPool&lt;/STRONG&gt;). This controller relies on 2 external jar files (provided by Virtuoso)&amp;nbsp;that I have placed inside a /libs folder under the module that implements the interface of my service. I have pointed to these jars as dependencies in the pom.xml of that same module and maven is able to import them. Furthermore, I am able to successfully compile and run a JUnit test of my implementation of the service which consists of simply getting a connection and checking if it is open.&lt;BR /&gt;&lt;BR /&gt;The problem arises when I compile my service into a NAR and then deploy that service in NiFi. NiFi is able to detect it but when I try to enable it, it throws a&amp;nbsp;NoClassDefFoundError that is related to these external jars. Now I am considering doing similarly to &lt;STRONG&gt;DBCPConnectionPool&amp;nbsp;&lt;/STRONG&gt;and create a property to point to these jars and load them externally, however, I simply do not understand what is causing the problem and I am too curious to let it go, I am also concerned that this approach may not be viable for these jars. So i am curious if someone can point me in the right way.&lt;BR /&gt;Here is my folder structure:&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/28761i4F53FF9897BE53BF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Here is the code I am trying to execute&amp;nbsp;&lt;EM&gt;@OnEnabled. which passes JUnit&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="java"&gt;@OnEnabled
    public void onEnabled(final ConfigurationContext context) {

        getLogger().info("Initializing Virtuoso Repository");

        try {
            ConnectionPoolDataSource dataSource = new VirtuosoConnectionPoolDataSource();
            ((VirtuosoConnectionPoolDataSource)dataSource).setCharset(context.getProperty(REPOSITORY_CHARSET).getValue());
            ((VirtuosoConnectionPoolDataSource)dataSource).setServerName(context.getProperty(REPOSITORY_SERVER).getValue());
            ((VirtuosoConnectionPoolDataSource)dataSource).setInitialPoolSize(Integer.parseInt(context.getProperty(REPOSITORY_CONNECTIONPOOLSIZE).getValue()));
            ((VirtuosoConnectionPoolDataSource)dataSource).setMaxPoolSize(Integer.parseInt(context.getProperty(REPOSITORY_MAXCONNECTIONPOOLSIZE).getValue()));
            repository = new VirtuosoRepository(dataSource, context.getProperty(REPOSITORY_DEFAULTGRAPH).getValue(), true);
            repository.initialize();
        }catch (Exception e){
            getLogger().error("Unable to Initialize Virtuoso Repository", e);

        }

    }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the pom where/how I declare the jar dependencies (This is where I am assuming the error might be)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 400px;"&gt;&lt;img src="https://community.cloudera.com/t5/image/serverpage/image-id/28762i7C5DD86B12082CF0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;And this is the log of the error I am getting when I try to enable it from NiFi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;2020-08-31 13:50:03,567 ERROR [Timer-Driven Process Thread-4] o.a.n.c.s.StandardControllerServiceNode Failed to invoke @OnEnabled method of StandardMyService[id=43ef57e8-0174-1000-843d-d32a07ba02bb] due to java.lang.NoClassDefFoundError: virtuoso/jdbc4/VirtuosoConnectionPoolDataSource
2020-08-31 13:50:03,567 ERROR [Timer-Driven Process Thread-4] e.e.c.dct.Virtuoso.StandardMyService StandardMyService[id=43ef57e8-0174-1000-843d-d32a07ba02bb] Could not Shut Down Repository: java.lang.NullPointerException
java.lang.NullPointerException: null
	at eu.everis.cordis.dct.Virtuoso.StandardMyService.shutdown(StandardMyService.java:187)
	at jdk.internal.reflect.GeneratedMethodAccessor376.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.apache.nifi.util.ReflectionUtils.invokeMethodsWithAnnotations(ReflectionUtils.java:142)&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope someone can explain where the problem comes from,&lt;BR /&gt;BR,&lt;BR /&gt;Tino&lt;/P&gt;</description>
      <pubDate>Tue, 01 Sep 2020 12:48:12 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-custom-controller-using-external-jars/m-p/302183#M221019</guid>
      <dc:creator>Constan</dc:creator>
      <dc:date>2020-09-01T12:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: NoClassDefFoundError custom controller using external jars</title>
      <link>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-custom-controller-using-external-jars/m-p/302313#M221072</link>
      <description>&lt;P&gt;An update since I managed to solve the issue. I followed the advice given in this StackOverflow post&amp;nbsp;&lt;A href="https://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them" target="_blank"&gt;https://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them&lt;/A&gt;&amp;nbsp;by creating a static in-project repository so that maven can have better access to the jars. It seemed to do the trick.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Sep 2020 13:35:51 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Support-Questions/NoClassDefFoundError-custom-controller-using-external-jars/m-p/302313#M221072</guid>
      <dc:creator>Constan</dc:creator>
      <dc:date>2020-09-03T13:35:51Z</dc:date>
    </item>
  </channel>
</rss>

