Multi-module spring-boot project, container can't be started, got Error "Could not find or load main class"
See original GitHub issueEnvironment:
- *Jib version: * 2.2.0
- Build tool: Maven 3.6.3
- *OS: * Windows 10
Description of the issue: Hello,
i have a multi-module spring-boot-project, as follows the project structure: (root - Parent Project “Zi_DeliveryService”) ± delivery-service # Sub-Module with a main class, it has module “delivery-common” as dependency ± delivery-common #Sub-Module, does not have main class
However, by running “mvn clean deploy jib:build” in the root, the image can be built and pushed into image-repo, but the container cannot be started, and the error message is “Could not find or load main class com.zi.delivery.Application”.
If i want to containerize the sub-module, by runing “mvn clean package jib:build -pl delivery-service -am” Image can not even be built, I got unauthorized error
Ways to reproduce:
Way 1.
If i run Jenkins-Skript:
sh ‘mvn clean deploy jib:build -Dmaven.test.skip=true -Djib.from.auth.username=$imageRepoUser -Djib.from.auth.password=$imageRepoPassword -Djib.to.auth.username=$imageRepoUser -Djib.to.auth.password=$imageRepoPassword’
Image can be built and pushed to image-repo, no unauthorized error. But Container cannot be started, Error message: “Could not find or load main class com.zi.delivery.Application” in the pod
Way 2. Jenkins-Skript: sh ‘mvn clean deploy jib:build -pl delivery-service -am -Dmaven.test.skip=true -Djib.from.auth.username=$imageRepoUser -Djib.from.auth.password=$imageRepoPassword -Djib.to.auth.username=$imageRepoUser -Djib.to.auth.password=$imageRepoPassword’
The jenkins-job will fail and the error message is: [ERROR] I/O error for image [harbor.zi.com:443/open-jdk-8u242-base-image]: [ERROR] java.net.SocketException [ERROR] Socket closed [INFO] ------------------------------------------------------------------------ [INFO] ZiDeliveryService …SUCCESS [ 13.479 s] [INFO] delivery-common …SUCCESS [ 4.247 s] [INFO] delivery-service …FAILURE [ 8.629 s] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:2.2.0:build (default-cli) on project delivery-service: Build image failed, perhaps you should make sure your credentials for ‘harbor.zi.com:443’ are set up correctly. Unauthorized for harbor.zi.com:443: 500 Internal Server Error -> [Help 1]
Details: (1) There is @SpringBootApplication Annotation in the main Class (2) I only wrote one main class, which is in the delivery-service module (3) In the parent-pom, the jib-plugin is in the part PluginManagement; in the child-pom of module “delivery-service”, i must specify the mainClass with <mainClass>com.zi.delivery.Application</mainClass>, otherwise the error message will be “Could not find or load main class ${start-class}”; in the child-pom of the module “delivery-common”, i set jib.skip as true.
jib-maven-plugin
Configuration in parent pom:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<version>${jib-maven-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
jib-maven-plugin
Configuration in child pom of the module “delivery-service”, which contains a main class:
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>jib-maven-plugin</artifactId>
<configuration>
<container>
<mainClass>com.zi.delivery.Application</mainClass>
<jvmFlags>
<jvmFlag>-Xmx3G</jvmFlag>
</jvmFlags>
</container>
<from>
<image>${image.from}</image>
</from>
<to>
<image>${image.to}</image>
<tags>
<tag>${project.version}</tag>
<tag>${image.tag}</tag>
</tags>
</to>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.zi.delivery.Application</mainClass>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
jib-maven-plugin
Configuration in child pom of the other module “delivery-common”, which does not have any main class, and jib.skip is set as true:
<properties>
<jib.skip>true</jib.skip>
</properties>
Please give me some advise, thank you very much.
Best regards, Zi
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (3 by maintainers)
Top GitHub Comments
Hi @chanseokoh,
today i tried the following and the Error “Could not find or load main class” is gone, and i can build and push image to harbor, and i also can start container.
What i did:
1. parent-pom: only do one thing, set jib in as profile
2. In the module with mainClass, in my use-case “delivery-service”
set NOTHING regarding jib
set “spring-boot-maven-plugin” as follows:
I refered to the link https://github.com/GoogleContainerTools/jib/issues/1539 , and the answer from andxu
3. In all the other modules, without mainClass, set jib.skip, in my use-case “delivery-common”
4. Run with
mvn clean deploy jib:build -Pjib -Dmaven.test.skip=true -Djib.from.auth.username=$harboruser -Djib.from.auth.password=$harborpassword -Djib.to.auth.username=$harboruser -Djib.to.auth.password=$harborpassword
PS: at the end, through it works. But, i could not explain, why i cannot jib:build locally in console and get the Unauthorized 500 Internal Server Error from Harbor, and why it only works via jenkins-job.
BR, Zi
Hi @chanseokoh
thank you very much!
Yes, as you said, in my case, the problem is, spring-boot-maven-plugin runs in both delivery-service and deliver-common, as this plugin is defined in <pluginManagement>, and run in all sub-modules, so <goal>repackage</goal> is set in the module with mainClass and not only .jar file, but also a .jar.original file is created in this sub-module.
I am thinking maybe some configuration is missing in my computer (proxy or something else), i am trying to set no_proxy for the harbor link on my computer. If i can do it sucessfully, I will give an update here.
BR, Zi