java.lang.NoClassDefFoundError: com/inductiveautomation/perspective/gateway/api/PerspectiveContext

I am trying to learn how to successfully build a custom module for Ignition Perspective but I am running into an issue. I have added a simple react component and built my project successfully and I get the .modl file but when I Ignition tries to load the module it fails with

java.lang.NoClassDefFoundError: com/inductiveautomation/perspective/gateway/api/PerspectiveContext

I have triple checked against the sample project provided by IA but I am not able to find where I went wrong.

PerspectiveContext imports fine with no errors

import java.util.Optional;
import ca.on.listech.perspectivematerial.common.PerspectiveMaterialModule;
import ca.on.listech.perspectivematerial.common.components.TextField;
import com.inductiveautomation.ignition.common.licensing.LicenseState;
import com.inductiveautomation.ignition.common.util.LoggerEx;
import com.inductiveautomation.ignition.gateway.model.AbstractGatewayModuleHook;
import com.inductiveautomation.ignition.gateway.model.GatewayContext;
import com.inductiveautomation.perspective.common.api.ComponentRegistry;
import com.inductiveautomation.perspective.gateway.api.PerspectiveContext;

but when attempting to get the PerspectiveContext it's failing. Here is the startup method where the error it occurring

@Override
    public void startup(LicenseState licenseState) {
        log.info("Starting up Perspective Material Hook");

        this.perspectiveContext = PerspectiveContext.get(this.gatewayContext);
        this.componentRegistry = this.perspectiveContext.getComponentRegistry();

        if (this.componentRegistry != null) {
            log.info("Registering Components");
            this.componentRegistry.registerComponent(TextField.DESCRIPTOR);
        } else {
            log.error("Reference to component registry not found, PM Components will fail to function!");
        }
    }

Any ideas?

Can you share your build file? It's likely that your resulting module.xml doesn't declare its dependency on the Perspective module.

1 Like

I think you are right I do not have this line in my module.xml file

<depends scope="DG">com.inductiveautomation.perspective</depends>

That was definitely right! I'm still getting more errors but it's no longer that one.

Thanks! I will continue to try and sort these errors out on my own

1 Like

I am getting the same error and I don't understand the proposed solution to this thread. I have the perspective-gateway from com.inductiveautomation.ignitionsdk in my gateway pom file. My IDE has no problem autocompleting the imports. Is this the correct dependency?

What's in my pom:

<dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>perspective-gateway</artifactId>
            <version>${ignition-sdk-version}</version> <!-- we use version 8.1.33 -->
            <type>pom</type>
            <scope>provided</scope>
</dependency>

There is a separate section in your pom.xml where you add settings that end up in the module.xml file, and one of those settings declares what other modules your module depends on. It's not the same thing as declaring a Maven dependency.

It's equivalent to this section of the device example that declares itself dependent on the OPC UA module: ignition-sdk-examples/opc-ua-device/opc-ua-device-build/pom.xml at 276f89239073e2108253716bce7f4ff70d20698d · inductiveautomation/ignition-sdk-examples · GitHub

Ahh, that makes sense, Thank you!