0

I am getting the below error in my GCP Cloud Run service:

Error: Could not find or load main class com.sdas.demo.sd.Application
Caused by: java.lang.ClassNotFoundException: com.sdas.demo.sd.Application

What I was doing:

  1. I have a spring boot application where I used jib-maven-plugin. In BitBucket pipeline, I was executing the below command:

    mvn clean compile com.google.cloud.tools:jib-maven-plugin:3.1.4:build -Dimage=eu.gcr.io/sdas-demo-dev/temp-service

  2. After that deploying this GCR image to Cloud Run using gcloud command from BitBucket pipeline. This deployment failed with the error that 'Could not load main class'.

But if I run the mvn clean compile com.google.cloud.tools:jib-maven-plugin:3.1.4:build -Dimage=eu.gcr.io/sdas-demo-dev/temp-service from my computer git bash for the same spring boot application code and then deploy it to Cloud Run (via gcloud command or via console or via pipeline); it's deployed successfully.

I used 'mainClass' tag under jib-maven-plugin in pom.xml. But still it is unable to find or load the main class.

Can anyone help how to identify the problem? Is this a classpath issue or environment issue?

Soumik Das
  • 156
  • 11
  • I feel like I'm missing some information. Could you please elaborate a bit more on how to reproduce the method that fails to deploy and the working one? – Lluís Muñoz Oct 01 '21 at 12:36
  • After some little investigation, I found that the jib-maven-plugin is unable to compile source code when running from BitBucket pipeline. That means, the target/classes directory is missing all the classes of my application. Thus when jib is making the image, it is missing the classes. But the funny part is, when I am running the mvn clean compile jib:build from my local git bash, it is able to compile all the classes and the image is working fine. I suspect the the bitbucket image is missing jvm. – Soumik Das Oct 01 '21 at 16:01
  • Minor correction: it's the `maven-compiler-plugin` that compiles source files and creates `.class` files under `target/classes`, not `jib-maven-plugin`. – Chanseok Oh Oct 01 '21 at 17:28

1 Answers1

1

Issue sorted now.

Root cause:

  • 'No resources found to compile' - I found this message in the build log. This message remind me something wrong within the application package.
  • My system is running on Windows 10 and my application directory starting with 'Java.com.demo.sdas' (J in capital). Since Windows is case in sensitive; it is not causing an issue.
  • BitBucket pipeline running on Linux server and it is case sensitive. Thus it is unable to find the application directory starting with 'Java.com.demo.sdas'.

Solution: Renamed the directory as 'java' and then everything is working as expected.

Soumik Das
  • 156
  • 11