How to resolve java.lang.NoClassDefFoundError: io/grpc/BindableService

Experts,
I am new to temporal and exploring its basic,I tried running the basic java but getting the following exception "java.lang.NoClassDefFoundError: io/grpc/BindableService ".

Temporal Version: 28 and is up and running

Following are the jars used

  1. commons-configuration2-2.7.jar
  2. grpc-stub-1.31.0.jar
  3. logback-classic-1.2.3.jar
  4. protobuf-java-2.0.1.jar
  5. slf4j-api-1.7.30.jar
  6. temporal-sdk-0.28.0.jar

Sample Java:
Referred https://docs.temporal.io/docs/java-quick-start/ GettingStarted progm.
Exception: When i try to run this from my Eclipse it gives following exception
Exception in thread ā€œmainā€ java.lang.NoClassDefFoundError: io/grpc/BindableService
at io.temporal.serviceclient.WorkflowServiceStubs.newInstance(WorkflowServiceStubs.java:34)
at com.sci.sample.helloWorld.GettingStarted.main(GettingStarted.java:37)
Caused by: java.lang.ClassNotFoundException: io.grpc.BindableService

Sample Java:
package com.sci.sample.helloWorld;

import org.slf4j.Logger;

import io.temporal.client.WorkflowClient;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.worker.Worker;
import io.temporal.worker.WorkerFactory;
import io.temporal.workflow.Workflow;
import io.temporal.workflow.WorkflowInterface;
import io.temporal.workflow.WorkflowMethod;

public class GettingStarted {

//private static Logger logger = Workflow.getLogger(GettingStarted.class);

@WorkflowInterface
public interface HelloWorld {

	@WorkflowMethod
	void sayHello(String name);
}

public static class HelloWorldImpl implements HelloWorld {

	@Override
	public void sayHello(String name) {
		System.out.println("Hello " + name + "!");
	}

}

public static void main(String[] args) {
	try {
		System.out.println("--STARTING--");
		// gRPC stubs wrapper that talks to the local docker instance of temporal service.
		WorkflowServiceStubs service = WorkflowServiceStubs.newInstance();
		// client that can be used to start and signal workflows
		WorkflowClient client = WorkflowClient.newInstance(service);
		// worker factory that can be used to create workers for specific task queues
		WorkerFactory factory = WorkerFactory.newInstance(client);
		Worker worker = factory.newWorker("HelloWorldTaskQueue");
		worker.registerWorkflowImplementationTypes(HelloWorldImpl.class);
		factory.start();
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	
}

}

1 Like

how did you set up the project , downloading the samples and importing as a gradle project worked for me, it brought all the dependencies.

However i tried with 0.23.0, but i donā€™t think it should be any different in 0.28.0.

1 Like

Thanks Madhu,

Initially i took the v28 > imported it on my STS > did the build. Build was successful but while running from STS i was getting this exception.

Now i build the the project > imported on my STS. In this case i am able to successfully run the app.

2 Likes

This is happening again with SDK 1.8.1, it specifies range and pulls 4.0-rc of protobuf please. When I explicitly set dependency to 3.19.4 my project compiles and tests are passing.

com.google.protobuf
protobuf-java-util
3.19.4

please fix version in SDK

gRPC version range has been removed in 1.8.1 (see commit here which is included in 1.8.1).

Iā€™m unable to reproduce 1.8.1 depends pulling proto 4.0.0-rc1 (nor rc2), can you help me reproduce? Share your ā€œgradle dependenciesā€ output if possible.

SDK defines a range here but has set 3.19.4 as preferred, which should be the one being pulled.

@Konstantin_Ignatyev we have just further restricted the proto range, see diff here. This will be part of the next SDK release.

<?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/maven-v4_0_0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.xpansiv.workflows</groupId>
    <artifactId>wf-common</artifactId>
    <version>2.0.${release}</version>
    <packaging>jar</packaging>

    <name>wf-common</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>8</java.version>
        <junit.version>4.13.2</junit.version>
        <release>0-SNAPSHOT</release>
        <temporalio.version>1.8.1</temporalio.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.temporal</groupId>
            <artifactId>temporal-sdk</artifactId>
            <version>${temporalio.version}</version>
        </dependency>
        <dependency>
            <groupId>org.awaitility</groupId>
            <artifactId>awaitility</artifactId>
            <version>4.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.12.0</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.11.0</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.35</version>
        </dependency>
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>31.1-jre</version>
        </dependency>
        <!--dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java-util</artifactId>
            <version>3.19.4</version>
        </dependency-->


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.temporal</groupId>
            <artifactId>temporal-testing</artifactId>
            <version>${temporalio.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.35</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <includes>
                        <include>*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <executions>
                    <execution>
                        <id>attach-sources</id>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>integration</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>3.0.0-M5</version>
                        <configuration>
                            <includes>
                                <include>*TestIntegration.java</include>
                            </includes>
                            <threadCount>1</threadCount>
                            <!-- test for EMA certs config -->
                            <!--systemProperties>
                                <property>
                                    <name>javax.net.ssl.keyStore</name>
                                    <value>../ema/.secrets/cacerts</value>
                                </property>
                                <property>
                                    <name>javax.net.ssl.trustStore</name>
                                    <value>/Users/kignatyev/dev/ema/.secrets/registryTrustKey.jks</value>
                                </property>
                                <property>
                                    <name>javax.net.ssl.trustStorePassword</name>
                                    <value>abcd1234</value>
                                </property>
                                <property>
                                    <name>javax.net.ssl.keyStorePassword</name>
                                    <value>changeit</value>
                                </property>
                                <property>
                                    <name>java.protocol.handler.pkgs</name>
                                    <value>com.sun.net.ssl.internal.www.protocol</value>
                                </property>
                                <property>
                                    <name>javax.net.ssl.keyStoreType</name>
                                    <value>JKS</value>
                                </property>
                            </systemProperties-->
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

    <distributionManagement>
        <repository>
            <id>xpansiv-artifactory</id>
            <name>artifactory-releases</name>
            <url>https://xpansiv.jfrog.io/artifactory/default-maven-virtual</url>
        </repository>
        <snapshotRepository>
            <id>xpansiv-artifactory</id>
            <name>artifactory-snapshots</name>
            <url>https://xpansiv.jfrog.io/artifactory/default-maven-virtual</url>
        </snapshotRepository>
    </distributionManagement>

</project>

mvn dependency:tree output
[INFO] Scanning for projectsā€¦
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.xpansiv.workflows:wf-common:jar:2.0.0-SNAPSHOT
[WARNING] ā€˜versionā€™ contains an expression but should be a constant. @ com.xpansiv.workflows:wf-common:2.0.${release}, /Users/kignatyev/dev/reprocases/temporal/pom.xml, line 9, column 14
[WARNING] ā€˜build.plugins.plugin.versionā€™ for org.apache.maven.plugins:maven-source-plugin is missing. @ com.xpansiv.workflows:wf-common:2.0.${release}, /Users/kignatyev/dev/reprocases/temporal/pom.xml, line 101, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
Downloading from xpansiv-artifactory: JFrog
Progress (1): 1.0 kB

Downloaded from xpansiv-artifactory: JFrog (1.0 kB at 550 B/s)
[INFO]
[INFO] ------------------< com.xpansiv.workflows:wf-common >-------------------
[INFO] Building wf-common 2.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[WARNING] The POM for io.temporal:temporal-test-server:jar:1.8.1 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The artifact org.slf4j:slf4j-log4j12:jar:1.7.35 has been relocated to org.slf4j:slf4j-reload4j:jar:1.7.35
[INFO]
[INFO] ā€” maven-dependency-plugin:2.8:tree (default-cli) @ wf-common ā€”
[WARNING] The artifact org.slf4j:slf4j-log4j12:jar:1.7.35 has been relocated to org.slf4j:slf4j-reload4j:jar:1.7.35
[INFO] com.xpansiv.workflows:wf-common:jar:2.0.0-SNAPSHOT
[INFO] Ā± io.temporal:temporal-sdk:jar:1.8.1:compile
[INFO] | Ā± io.temporal:temporal-serviceclient:jar:1.8.1:compile
[INFO] | | Ā± io.grpc:grpc-api:jar:1.44.1:compile
[INFO] | | | - io.grpc:grpc-context:jar:1.44.1:compile
[INFO] | | Ā± io.grpc:grpc-stub:jar:1.44.1:compile
[INFO] | | Ā± io.grpc:grpc-netty-shaded:jar:1.44.1:compile
[INFO] | | | - io.perfmark:perfmark-api:jar:0.23.0:runtime
[INFO] | | Ā± com.google.protobuf:protobuf-java-util:jar:4.0.0-rc-2:compile (version selected from constraint [3.10.0,))
[INFO] | | | - com.google.protobuf:protobuf-java:jar:4.0.0-rc-2:compile
[INFO] | | Ā± com.uber.m3:tally-core:jar:0.11.1:compile (version selected from constraint [0.4.0,))
[INFO] | | Ā± io.grpc:grpc-core:jar:1.44.1:compile
[INFO] | | | Ā± com.google.android:annotations:jar:4.1.1.4:runtime
[INFO] | | | - org.codehaus.mojo:animal-sniffer-annotations:jar:1.19:runtime
[INFO] | | - io.grpc:grpc-services:jar:1.44.1:runtime
[INFO] | | - io.grpc:grpc-protobuf:jar:1.44.1:runtime
[INFO] | | Ā± com.google.api.grpc:proto-google-common-protos:jar:2.0.1:runtime
[INFO] | | - io.grpc:grpc-protobuf-lite:jar:1.44.1:runtime
[INFO] | Ā± com.google.code.gson:gson:jar:2.9.0:compile (version selected from constraint [2.0,))
[INFO] | Ā± io.micrometer:micrometer-core:jar:1.8.3:compile
[INFO] | | Ā± org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
[INFO] | | - org.latencyutils:LatencyUtils:jar:2.0.3:runtime
[INFO] | Ā± com.fasterxml.jackson.core:jackson-databind:jar:2.13.1:compile
[INFO] | | Ā± com.fasterxml.jackson.core:jackson-annotations:jar:2.13.1:compile
[INFO] | | - com.fasterxml.jackson.core:jackson-core:jar:2.13.1:compile
[INFO] | Ā± com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.13.1:runtime
[INFO] | Ā± com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.13.1:runtime
[INFO] | - javax.annotation:javax.annotation-api:jar:1.3.2:runtime
[INFO] Ā± org.awaitility:awaitility:jar:4.2.0:compile
[INFO] | - org.hamcrest:hamcrest:jar:2.1:compile
[INFO] Ā± org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] Ā± commons-io:commons-io:jar:2.11.0:compile
[INFO] Ā± org.slf4j:slf4j-api:jar:1.7.35:compile
[INFO] Ā± com.google.guava:guava:jar:31.1-jre:compile
[INFO] | Ā± com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] | Ā± com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] | Ā± com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] | Ā± org.checkerframework:checker-qual:jar:3.12.0:compile
[INFO] | Ā± com.google.errorprone:error_prone_annotations:jar:2.11.0:compile
[INFO] | - com.google.j2objc:j2objc-annotations:jar:1.3:compile
[INFO] Ā± junit:junit:jar:4.13.2:test
[INFO] | - org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] Ā± io.temporal:temporal-testing:jar:1.8.1:test
[INFO] | - io.temporal:temporal-test-server:jar:1.8.1:test
[INFO] - org.slf4j:slf4j-reload4j:jar:1.7.35:test
[INFO] - ch.qos.reload4j:reload4j:jar:1.2.18.3:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.815 s
[INFO] Finished at: 2022-03-21T14:55:46-07:00
[INFO] ------------------------------------------------------------------------

Thanks, with Maven I also get:

com.google.protobuf:protobuf-java-util:jar:4.0.0-rc-2:compile (version selected from constraint [3.10.0,))

pulled from the temporal-sdk depends. This does not happen when using Gradle.

Opened issue in Java SDK to make sure we test the recently added range restriction for next release.

Tested with 1.9.0-SNAPSHOT and the added restriction to the version range no longer pulls from 4.x (it will still for Maven pull the latest 3.x just fyi).
You can set it also manually to 3.19.4, as thatā€™s the preferred version set if you use Gradle.

Hope this helps.