1

I have a Spring boot application which has many modules like error module, persistency, controllers etc like below

--Application
  |
  -- error module
  |
  -- controllers module
  |
  -- Persistancy module
  |
  -- .....

To build docker image for this using Maven jib plugin with below configuration in pom.xml

    <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>jib-maven-plugin</artifactId>
        <version>2.4.0</version>
        <configuration>
          <to>
            <image>some.repo.io/my_name/jib-test</image>
          </to>
          <container>
            <mainClass>com.a.b.c.Application</mainClass>
            <ports>
              <port>8080</port>
            </ports>
          </container>
        </configuration>
    </plugin>

Build is successful. But when I run the image, its throwing error Error: Could not find or load the main class com.a.b.c.Application.

How can I build the image using Jib ?. What am I missing here?

Santosh Hegde
  • 3,420
  • 10
  • 35
  • 51
  • You can try without `` and see will it infer it correctly. Other than that, it looks like it is explained in the docs. – Stefan Golubović Jul 24 '20 at 14:39
  • [ERROR] Failed to execute goal com.google.cloud.tools:jib-maven-plugin:2.4.0:dockerBuild (default-cli) on project asset-error: Main class was not found, perhaps you should add a `mainClass` configuration to jib-maven-plugin -> [Help 1] Getting this error – Santosh Hegde Jul 24 '20 at 14:57
  • Do you have main class, the one annotated with `@SpringBootApplication`? – Stefan Golubović Jul 24 '20 at 15:02
  • Yes. But it's inside a module. Not at the root of the project – Santosh Hegde Jul 24 '20 at 15:14
  • Doesn't matter, it will be picked up. You can try `mvn clean package` and `java -jar /path/to/generated/jar` to verify that it starts correctly. If it does, maybe you try specifying `from` image. Maybe the default one is missing something somehow. – Stefan Golubović Jul 24 '20 at 15:29
  • 2
    Not sure if this will help, but take a look at https://github.com/GoogleContainerTools/jib/issues/2483 If you still can't resolve the issue, you may open a new issue on the Jib repo with a sample to reproduce. – Chanseok Oh Jul 24 '20 at 16:17
  • 2
    And this [SO answer](https://stackoverflow.com/a/51705181/1701388) has a link to a working multi-module Spring Boot example ([learnmake-microservices](https://github.com/CapgeminiNorway/learnmake-microservices)), so you might want to take a look at that too. – Chanseok Oh Jul 24 '20 at 16:20

1 Answers1

0

In your pom.xml, add:

<modules>
    <module>error</module>
    <module>controllers </module>
    <module>Persistancy </module>
</modules>

Then run the following from your terminal:

mvn -Pprod verify com.google.cloud.tools:jib-maven-plugin:dockerBuild
Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99