NoClassDefFoundError persepective-component

NoClassDefFoundError

Currntly i'm trying to use the persepective-component example to create a component in an existing ignition module. I coppied over the code from example and then found the mavern equivalent dependines since the example is based on Gradle. My dev environment matches the versuins listed below. I've also added the code snippet where the error is thrown.


Example Link: https://github.com/inductiveautomation/ignition-sdk-examples/tree/master/perspective-component

Dependencies

groupId artifactId version scope
com.inductiveautomation.perspective perspective-gateway 2.1.25 provided
com.inductiveautomation.ignitionsdk perspective-common 8.1.25 provided
com.inductiveautomation.ignitionsdk ignition-common 8.1.25 provided
com.inductiveautomation.ignitionsdk gateway-api 8.1.25 provided

Gateway Error

java.lang.NoClassDefFoundError: com/inductiveautomation/perspective/gateway/api/PerspectiveContext
at ami.GatewayHook.startup(GatewayHook.java:63)
at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl$LoadedModule.startup(ModuleManagerImpl.java:2439)
at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl.startupModule(ModuleManagerImpl.java:1232)
at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl$2.call(ModuleManagerImpl.java:777)
at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl.executeModuleOperation(ModuleManagerImpl.java:953)
at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl.installModuleInternal(ModuleManagerImpl.java:743)
at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl$InstallCommand.execute(ModuleManagerImpl.java:1909)
at com.inductiveautomation.ignition.gateway.modules.ModuleManagerImpl$Receiver.receiveCall(ModuleManagerImpl.java:1862)
at com.inductiveautomation.ignition.gateway.redundancy.QueueableMessageReceiver.receiveCall(QueueableMessageReceiver.java:47)
at com.inductiveautomation.ignition.gateway.redundancy.RedundancyManagerImpl.dispatchMessage(RedundancyManagerImpl.java:1030)
at com.inductiveautomation.ignition.gateway.redundancy.RedundancyManagerImpl$ExecuteTask.run(RedundancyManagerImpl.java:1098)
at com.inductiveautomation.ignition.common.execution.impl.BasicExecutionEngine$ThrowableCatchingRunnable.run(BasicExecutionEngine.java:544)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.base/java.util.concurrent.FutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.inductiveautomation.perspective.gateway.api.PerspectiveContext
at java.base/java.net.URLClassLoader.findClass(Unknown Source)
at com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:37)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)
at com.inductiveautomation.ignition.gateway.modules.ModuleClassLoader.loadClass(ModuleClassLoader.java:85)
at java.base/java.lang.ClassLoader.loadClass(Unknown Source)

Code Snippet

@Override
public void startup(LicenseState licenseState) {
    this.perspectiveContext = PerspectiveContext.get(this.gatewayContext);  //LINE 63: Error is Thrown
    this.componentRegistry = this.perspectiveContext.getComponentRegistry();
    this.modelDelegateRegistry = this.perspectiveContext.getComponentModelDelegateRegistry();

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

    if (this.modelDelegateRegistry != null) {
        log.info("Registering model delegates.");
        this.modelDelegateRegistry.register(Messenger.COMPONENT_ID, MessageComponentModelDelegate::new);
    } else {
        log.error("ModelDelegateRegistry was not found!");
    }
}

You probably didn't build your module so that it indicates it depends on the Perspective module.

What does the pom.xml that configures the Ignition maven plugin look like?

Gateway pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>ami-mes</artifactId>
        <groupId>ami</groupId>
        <version>1.0.1</version>
    </parent>

    <artifactId>ami-mes-gateway</artifactId>

    <dependencies>

        <!-- https://mvnrepository.com/artifact/com.inductiveautomation.perspective/perspective-gateway -->
        <dependency>
            <groupId>com.inductiveautomation.perspective</groupId>
            <artifactId>perspective-gateway</artifactId>
            <version>2.1.25</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.websocket</groupId>
            <artifactId>javax.websocket-api</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>perspective-common</artifactId>
            <version>8.1.25</version>
            <scope>provided</scope>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>ignition-common</artifactId>
            <version>8.1.25</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>ignition-common</artifactId>
            <version>8.1.25</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>gateway-api</artifactId>
            <version>8.1.25</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>driver-api</artifactId>
            <version>8.1.25</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>ami</groupId>
            <artifactId>ami-mes-client</artifactId>
            <version>1.0.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>ami</groupId>
            <artifactId>ami-mes-common</artifactId>
            <version>1.0.1</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>compile</scope>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Common pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>ami-mes</artifactId>
        <groupId>ami</groupId>
        <version>1.0.1</version>
    </parent>

    <artifactId>ami-mes-common</artifactId>

    <dependencies>
        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>ignition-common</artifactId>
            <version>8.1.25</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>com.inductiveautomation.ignition</groupId>
            <artifactId>client-api</artifactId>
            <version>8.1.25</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>com.inductiveautomation.ignitionsdk</groupId>
            <artifactId>perspective-common</artifactId>
            <version>8.1.25</version>
            <type>pom</type>
            <scope>provided</scope>
        </dependency>


    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.2</version>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

No, not either of those. How are you building the .modl file? Are you not using the ignition-maven-plugin?

I pressume this is what your after since it references the mavern plugin. If not then i'll have to look into the matter and get back to you.

Build pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <artifactId>ami-mes</artifactId>
        <groupId>ami</groupId>
        <version>1.0.1</version>
    </parent>

    <artifactId>ami-mes-build</artifactId>
    <properties>
        <module-version>${project.parent.version}</module-version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>ami</groupId>
            <artifactId>ami-mes-client</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>ami</groupId>
            <artifactId>ami-mes-common</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>ami</groupId>
            <artifactId>ami-mes-designer</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
        <dependency>
            <groupId>ami</groupId>
            <artifactId>ami-mes-gateway</artifactId>
            <version>${project.parent.version}</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.inductiveautomation.ignitionsdk</groupId>
                <artifactId>ignition-maven-plugin</artifactId>
                <version>1.1.0</version>

                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>modl</goal>
                        </goals>
                    </execution>
                </executions>

                <configuration>
                    <projectScopes>
                        <projectScope>
                            <name>ami-mes-client</name>
                            <scope>C</scope>
                        </projectScope>
                        <projectScope>
                            <name>ami-mes-common</name>
                            <scope>CDG</scope>
                        </projectScope>
                        <projectScope>
                            <name>ami-mes-designer</name>
                            <scope>CD</scope>
                        </projectScope>
                        <projectScope>
                            <name>ami-mes-gateway</name>
                            <scope>G</scope>
                        </projectScope>
                    </projectScopes>

                    <moduleId>ami.ami-mes</moduleId>
                    <moduleName>${project.parent.name}</moduleName>
                    <moduleDescription>${project.description}</moduleDescription>
                    <moduleVersion>1.0.0</moduleVersion>
                    <requiredIgnitionVersion>8.1.25</requiredIgnitionVersion>


                    <hooks>
                        <hook>
                            <scope>C</scope>
                            <hookClass>ami.client.ClientHook</hookClass>
                        </hook>
                        <hook>
                            <scope>D</scope>
                            <hookClass>ami.designer.DesignerHook</hookClass>
                        </hook>
                        <hook>
                            <scope>G</scope>
                            <hookClass>ami.GatewayHook</hookClass>
                        </hook>
                    </hooks>

                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Yeah, it's missing a <depends> section that declares a dependency on the Perspective module, similar to this one used in the device example declaring a dependency on the OPC UA module.