How to dockerize a java app using Jib on the mac

Viewed 435

I am trying to dockerize my java web app by running the following dockerBuild command below to build a local image first. Keep in mind I am on the mac & am using Java 16 & the jib-maven-plugin for my project.

When I run the command, it gives the following error below.

Error

 Exception in thread "main" java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:567)
        at org.apache.maven.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:39)
        at org.apache.maven.wrapper.WrapperExecutor.execute(WrapperExecutor.java:122)
        at org.apache.maven.wrapper.MavenWrapperMain.main(MavenWrapperMain.java:61)
Caused by: java.lang.NoClassDefFoundError: org/apache/maven/exception/ExceptionHandler
        at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3334)
        at java.base/java.lang.Class.getMethodsRecursive(Class.java:3475)
        at java.base/java.lang.Class.getMethod0(Class.java:3461)
        at java.base/java.lang.Class.getMethod(Class.java:2193)
        at org.codehaus.plexus.classworlds.launcher.Launcher.getEnhancedMainMethod(Launcher.java:168)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:261)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
        ... 7 more
Caused by: java.lang.ClassNotFoundException: org.apache.maven.exception.ExceptionHandler
        at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
        at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
        ... 17 more

Command

./mvnw jib:dockerBuild -Djib.to.image=fullstack:v1

pom.xml

      <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>jib-maven-plugin</artifactId>
            <version>2.5.2</version>
            <configuration>
                <from>
                    <image>openjdk:16</image>
                </from>
                <container>
                    <ports>
                        <port>8080</port>
                    </ports>
                    <format>OCI</format>
                </container>
            </configuration>
        </plugin>

Could it be that the version of the jib-maven-plugin (2.5.2) is not compatible with Java 16?

2 Answers

I'm using jib also on mac.

According to this issue it seems that jib hasn't been tested against java 16. You can build with earlier versions (java 11 for instance) and still execute it on top of java 16 provided that your code compiles on earlier versions and you don't use java 16 features. Also make sure to use maven 3.8.1

Maybe the version of the jib-maven plugin (2.5.2) is not compatible with Java 16. I've used the latest version of JIB, and it works fine with the Java 16 on Mac.

 ...
  <build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>com.google.cloud.tools</groupId>
            <artifactId>jib-maven-plugin</artifactId>
            <version>${jib-maven-plugin.version}</version>
            <configuration>
                <to>
                    <image>jib-spring-boot-app</image>
                </to>
                <from>
                    <image>openjdk:16</image>
                </from>
                <container>
                    <ports>
                        <port>8080</port>
                    </ports>
                    <format>OCI</format>
                </container>
            </configuration>
        </plugin>
    </plugins>
</build>

<properties>
    <jib-maven-plugin.version>3.0.0</jib-maven-plugin.version>
    <java.version>1.16</java.version>
</properties>
...
Related