Jib: Only support tomcat?I used undertow

Created on 19 Jul 2018  Â·  22Comments  Â·  Source: GoogleContainerTools/jib

this my pom.xml

   <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>
    </dependencies>

docker run

 root@nasoft-virtual-machine:/usr/local/tools# docker logs -f 5a42c2075b9a
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
    at org.springframework.boot.SpringApplication.<clinit>(SpringApplication.java:179)
    at org.orh.Application.main(Application.java:13)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 2 more

If it is tomcat, no problem.

Most helpful comment

Hi @qq12157138, The reason is in your class the docker-maven-plugin depend on the spring-boot-maven-plugin and there are some differences in the dependencies processing between spring-boot-maven-plugin with jib-maven-plugin. I tested on spring-boot-maven-plugin by marking provided to java-servlet-api, however, when I run spring-boot:repackage the java-servlet-api still include in the final jar file, that is why the docker-maven-plugin run successfully.

All 22 comments

This is my other demo error

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.5.9.RELEASE)

2018-07-19 11:38:36.483  INFO 1 --- [           main] The following profiles are active: dev
2018-07-19 11:38:36.504  INFO 1 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@595f4da5: startup date [Thu Jul 19 11:38:36 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@2ad48653
2018-07-19 11:38:36.504  INFO 1 --- [           main] Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@595f4da5: startup date [Thu Jul 19 11:38:36 CST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@2ad48653
2018-07-19 11:38:36.636  WARN 1 --- [           main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [cn.gov.sach.cas.im.Application]; nested exception is org.springframework.core.NestedIOException: Failed to load class [javax.servlet.Filter]; nested exception is java.lang.ClassNotFoundException: javax.servlet.Filter
2018-07-19 11:38:36.636  WARN 1 --- [           main] Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [cn.gov.sach.cas.im.Application]; nested exception is org.springframework.core.NestedIOException: Failed to load class [javax.servlet.Filter]; nested exception is java.lang.ClassNotFoundException: javax.servlet.Filter
2018-07-19 11:38:36.644 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [cn.gov.sach.cas.im.Application]; nested exception is org.springframework.core.NestedIOException: Failed to load class [javax.servlet.Filter]; nested exception is java.lang.ClassNotFoundException: javax.servlet.Filter
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at cn.gov.sach.cas.im.Application.main(Application.java:32)
Caused by: org.springframework.core.NestedIOException: Failed to load class [javax.servlet.Filter]; nested exception is java.lang.ClassNotFoundException: javax.servlet.Filter
    at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:690)
    at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getInterfaces(ConfigurationClassParser.java:870)
    at org.springframework.context.annotation.ConfigurationClassParser.processInterfaces(ConfigurationClassParser.java:363)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:320)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:190)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:292)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
    ... 12 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:687)
    ... 21 common frames omitted

2018-07-19 11:38:36.644 ERROR 1 --- [           main] Application startup failed

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [cn.gov.sach.cas.im.Application]; nested exception is org.springframework.core.NestedIOException: Failed to load class [javax.servlet.Filter]; nested exception is java.lang.ClassNotFoundException: javax.servlet.Filter
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:181)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:308)
    at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:228)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:272)
    at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:92)
    at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:687)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:525)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107)
    at cn.gov.sach.cas.im.Application.main(Application.java:32)
Caused by: org.springframework.core.NestedIOException: Failed to load class [javax.servlet.Filter]; nested exception is java.lang.ClassNotFoundException: javax.servlet.Filter
    at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:690)
    at org.springframework.context.annotation.ConfigurationClassParser$SourceClass.getInterfaces(ConfigurationClassParser.java:870)
    at org.springframework.context.annotation.ConfigurationClassParser.processInterfaces(ConfigurationClassParser.java:363)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:320)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:190)
    at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:292)
    at org.springframework.context.annotation.ConfigurationClassParser.processConfigurationClass(ConfigurationClassParser.java:245)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:198)
    at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:167)
    ... 12 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.servlet.Filter
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.springframework.context.annotation.ConfigurationClassParser.asSourceClass(ConfigurationClassParser.java:687)
    ... 21 common frames omitted


Hi @qq12157138, Can you check your pom.xml file that include the dependency spring-boot-starter? In the case your file did not have that dependency please remove spring-boot-starter-logging in the <exclusions>, I mean your pom file should be:

   <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>
    </dependencies>

Because of excluding the spring-boot-starter-logging will exclude the loggers those need by Spring framework and that is the root cause of java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory.

For other your demo, can you share your pom.xml file or can your check your target package include the java servlet package or not.

@d5nguyenvan ,Thank you for answering my question.
But, My pom.xml doesn't make any changes, I used to use docker-maven-plugin It is ok。

This is my pom.xml using jib-maven-plugin, It runs an error


pom.xml

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>cn.gov.sach.cas</groupId>
        <artifactId>cas-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>cas-im</artifactId>
    <packaging>jar</packaging>
    <name>cas-im</name>
    <description>cas-im</description>

    <properties>
        <start-class>cn.gov.sach.cas.im.Application</start-class>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>cn.gov.sach.cas</groupId>
            <artifactId>cas-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>

        <dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>4.6</version>
        </dependency>
        <dependency>
            <groupId>com.github.danielwegener</groupId>
            <artifactId>logback-kafka-appender</artifactId>
            <version>0.1.0</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.codehaus.janino</groupId>
            <artifactId>janino</artifactId>
        </dependency>

        <!-- db -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>
        <!-- db end -->

        <!-- swagger start -->
        <dependency>
            <groupId>com.fasterxml</groupId>
            <artifactId>classmate</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency>
        <!-- swagger end -->

        <!-- api token web server -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.6.0</version>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>2.2.0</version>
        </dependency>
        <!-- api token web server end -->

        <!-- mybatis util -->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.25-incubating</version>
        </dependency>
        <!-- mybatis util end -->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>

        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.2.0</version>
        </dependency>

    </dependencies>

    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profileActive>dev</profileActive>
                <proRegistry>${docker.registry}</proRegistry>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profileActive>test</profileActive>
                <proRegistry>${docker.test.registry}</proRegistry>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <profileActive>prod</profileActive>
                <proRegistry>${docker.prod.registry}</proRegistry>
            </properties>
        </profile>
    </profiles>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes> 
                    <exclude>application-dev.*</exclude>
                    <exclude>application-prod.*</exclude>
                    <exclude>application-test.*</exclude>
                    <exclude>application.*</exclude>
                    <exclude>logback.xml</exclude>
                </excludes>
            </resource>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources/config</directory>
                <includes>
                    <include>application-${profileActive}.*</include>
                    <include>application.*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources/config/${profileActive}</directory>
                <filtering>true</filtering>
                <includes>
                    <include>*</include>
                </includes>
            </resource>

            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*Mapper.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>

        </resources>
        <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>0.9.6</version>
                <configuration>
                    <from>
                        <image>openjdk:8-jre-alpine</image>
                    </from>
                    <to>
                        <image>${proRegistry}/${profileActive}/${project.name}</image>
                    </to>
                    <allowInsecureRegistries>true</allowInsecureRegistries>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

This is my pom.xml using docker-maven-plugin, it is ok!


pom.xml

<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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>cn.gov.sach.cas</groupId>
        <artifactId>cas-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <artifactId>cas-im</artifactId>
    <packaging>jar</packaging>
    <name>cas-im</name>
    <description>cas-im</description>

    <properties>
        <start-class>cn.gov.sach.cas.im.Application</start-class>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>

        <dependency>
            <groupId>cn.gov.sach.cas</groupId>
            <artifactId>cas-common</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.session</groupId>
            <artifactId>spring-session-data-redis</artifactId>
        </dependency>
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.3.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>

        <dependency>
            <groupId>org.jolokia</groupId>
            <artifactId>jolokia-core</artifactId>
        </dependency>

        <dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>4.6</version>
        </dependency>
        <dependency>
            <groupId>com.github.danielwegener</groupId>
            <artifactId>logback-kafka-appender</artifactId>
            <version>0.1.0</version>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>org.codehaus.janino</groupId>
            <artifactId>janino</artifactId>
        </dependency>

        <!-- db -->
        <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>
        </dependency>
        <!-- db end -->

        <!-- swagger start -->
        <dependency>
            <groupId>com.fasterxml</groupId>
            <artifactId>classmate</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency>
        <!-- swagger end -->

        <!-- api token web server -->
        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.6.0</version>
        </dependency>
        <dependency>
            <groupId>com.auth0</groupId>
            <artifactId>java-jwt</artifactId>
            <version>2.2.0</version>
        </dependency>
        <!-- api token web server end -->

        <!-- mybatis util -->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.25-incubating</version>
        </dependency>
        <!-- mybatis util end -->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-ribbon</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
        </dependency>

        <dependency>
            <groupId>redis.clients</groupId>
            <artifactId>jedis</artifactId>
            <version>2.9.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-logging</artifactId>
        </dependency>

        <dependency>
            <groupId>com.jayway.jsonpath</groupId>
            <artifactId>json-path</artifactId>
            <version>2.2.0</version>
        </dependency>

    </dependencies>

    <profiles>
        <profile>
            <id>dev</id>
            <properties>
                <profileActive>dev</profileActive>
                <proRegistry>${docker.registry}</proRegistry>
            </properties>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
        </profile>
        <profile>
            <id>test</id>
            <properties>
                <profileActive>test</profileActive>
                <proRegistry>${docker.test.registry}</proRegistry>
            </properties>
        </profile>
        <profile>
            <id>prod</id>
            <properties>
                <profileActive>prod</profileActive>
                <proRegistry>${docker.prod.registry}</proRegistry>
            </properties>
        </profile>
    </profiles>

    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
                <excludes> 
                    <exclude>application-dev.*</exclude>
                    <exclude>application-prod.*</exclude>
                    <exclude>application-test.*</exclude>
                    <exclude>application.*</exclude>
                    <exclude>logback.xml</exclude>
                </excludes>
            </resource>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources/config</directory>
                <includes>
                    <include>application-${profileActive}.*</include>
                    <include>application.*</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources/config/${profileActive}</directory>
                <filtering>true</filtering>
                <includes>
                    <include>*</include>
                </includes>
            </resource>

            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*Mapper.xml</include>
                </includes>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
            </resource>

        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.spotify</groupId>
                <artifactId>docker-maven-plugin</artifactId>
                <version>${docker.plugin.version}</version>
                <executions>
                    <execution>
                        <phase>deploy</phase>
                        <goals>
                            <goal>build</goal>
                            <goal>tag</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <serverId>docker-hub</serverId>
            <baseImage>registry.cn-hangzhou.aliyuncs.com/java-jdk/alpine-java-unlimited-jce:jdk8</baseImage>
                    <entryPoint>["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/${project.build.finalName}.jar"]
                    </entryPoint>
                    <imageName>${proRegistry}/${profileActive}/${project.name}:${version}</imageName>
                    <imageTags>
                        <imageTag>latest</imageTag>
                    </imageTags>
                    <resources>
                        <resource>
                            <targetPath>/</targetPath>
                            <directory>${project.build.directory}</directory>
                            <include>${project.build.finalName}.jar</include>
                        </resource>
                    </resources>
                    <image>${proRegistry}/${profileActive}/${project.name}:${version}</image>
                    <newName>${proRegistry}/${profileActive}/${project.name}</newName>
                    <forceTags>true</forceTags>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Thanks for your information, I see you included spring-boot-starter-logging in your pom.xml, I will perform some test and let you know soon :)

spring-boot-starter-logging will solve the first problem, but the second problem is not caused by spring-boot-starter-logging. I am not sure how to cause it.

Hi @qq12157138, Can you help me to get the content of metadata-v2.json under folder <your-project>\target\jib-cache to help me to understand the root cause (both of your cases) and the content of /app/libs in the docker was created by jib? Here are the example in my environment:

  • metadata-v2.json:
{"layers":[{"reference":{"size":13039636,"digest":"sha256:1ce09b4bdf18e38db4ea1464a3d08c7f6d84bdcf9293174208bfc5c7ded25048","diffId":"sha256:f81517fc98378f9b1406bd8df5b7ff606a5caa98597118663735c262eb3d1cdf"},"properties":{"layerEntries":[{"sourceFiles":["/Users/dukenguyen/.m2/repository/ch/qos/logback/logback-classic/1.1.11/logback-classic-1.1.11.jar","/Users/dukenguyen/.m2/repository/ch/qos/logback/logback-core/1.1.11/logback-core-1.1.11.jar","/Users/dukenguyen/.m2/repository/com/fasterxml/classmate/1.3.4/classmate-1.3.4.jar","/Users/dukenguyen/.m2/repository/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0.jar","/Users/dukenguyen/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.10/jackson-core-2.8.10.jar","/Users/dukenguyen/.m2/repository/com/fasterxml/jackson/core/jackson-databind/2.8.10/jackson-databind-2.8.10.jar","/Users/dukenguyen/.m2/repository/io/undertow/undertow-core/1.4.21.Final/undertow-core-1.4.21.Final.jar","/Users/dukenguyen/.m2/repository/io/undertow/undertow-servlet/1.4.21.Final/undertow-servlet-1.4.21.Final.jar","/Users/dukenguyen/.m2/repository/io/undertow/undertow-websockets-jsr/1.4.21.Final/undertow-websockets-jsr-1.4.21.Final.jar","/Users/dukenguyen/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar","/Users/dukenguyen/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar","/Users/dukenguyen/.m2/repository/org/glassfish/javax.el/3.0.0/javax.el-3.0.0.jar","/Users/dukenguyen/.m2/repository/org/hibernate/hibernate-validator/5.3.6.Final/hibernate-validator-5.3.6.Final.jar","/Users/dukenguyen/.m2/repository/org/jboss/logging/jboss-logging/3.3.1.Final/jboss-logging-3.3.1.Final.jar","/Users/dukenguyen/.m2/repository/org/jboss/spec/javax/annotation/jboss-annotations-api_1.2_spec/1.0.0.Final/jboss-annotations-api_1.2_spec-1.0.0.Final.jar","/Users/dukenguyen/.m2/repository/org/jboss/spec/javax/websocket/jboss-websocket-api_1.1_spec/1.1.0.Final/jboss-websocket-api_1.1_spec-1.1.0.Final.jar","/Users/dukenguyen/.m2/repository/org/jboss/xnio/xnio-api/3.3.8.Final/xnio-api-3.3.8.Final.jar","/Users/dukenguyen/.m2/repository/org/jboss/xnio/xnio-nio/3.3.8.Final/xnio-nio-3.3.8.Final.jar","/Users/dukenguyen/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.25/jcl-over-slf4j-1.7.25.jar","/Users/dukenguyen/.m2/repository/org/slf4j/jul-to-slf4j/1.7.25/jul-to-slf4j-1.7.25.jar","/Users/dukenguyen/.m2/repository/org/slf4j/log4j-over-slf4j/1.7.25/log4j-over-slf4j-1.7.25.jar","/Users/dukenguyen/.m2/repository/org/slf4j/slf4j-api/1.7.25/slf4j-api-1.7.25.jar","/Users/dukenguyen/.m2/repository/org/springframework/boot/spring-boot-autoconfigure/1.5.9.RELEASE/spring-boot-autoconfigure-1.5.9.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/boot/spring-boot-starter-logging/1.5.9.RELEASE/spring-boot-starter-logging-1.5.9.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/boot/spring-boot-starter-undertow/1.5.9.RELEASE/spring-boot-starter-undertow-1.5.9.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/boot/spring-boot-starter-web/1.5.9.RELEASE/spring-boot-starter-web-1.5.9.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/boot/spring-boot-starter/1.5.9.RELEASE/spring-boot-starter-1.5.9.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/boot/spring-boot/1.5.9.RELEASE/spring-boot-1.5.9.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/spring-aop/4.3.13.RELEASE/spring-aop-4.3.13.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/spring-beans/4.3.13.RELEASE/spring-beans-4.3.13.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/spring-context/4.3.13.RELEASE/spring-context-4.3.13.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/spring-core/4.3.13.RELEASE/spring-core-4.3.13.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/spring-expression/4.3.13.RELEASE/spring-expression-4.3.13.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/spring-web/4.3.13.RELEASE/spring-web-4.3.13.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/springframework/spring-webmvc/4.3.13.RELEASE/spring-webmvc-4.3.13.RELEASE.jar","/Users/dukenguyen/.m2/repository/org/yaml/snakeyaml/1.17/snakeyaml-1.17.jar"],"extractionPath":"/app/libs/"}],"lastModifiedTime":1531987007954}},{"reference":{"size":207,"digest":"sha256:556754082d8820dfb722657537bc2630a6fb20fdff729ca2452fd9327a227260","diffId":"sha256:3344fb9e85291a9c71bdb4f05f48cddb0281b4c7c3a6d4aad55d2864c66a6341"},"properties":{"layerEntries":[{"sourceFiles":["/Users/dukenguyen/Products/oss/spring-boot-sample-undertow/target/classes/application.properties"],"extractionPath":"/app/resources/"}],"lastModifiedTime":1531987006884}},{"reference":{"size":1686,"digest":"sha256:6c2df1b911269c038e7590a356a54b39f389fe051e57f70f4ca821f5d51e38d0","diffId":"sha256:adaa2b647640e3e9e86cbcbe970a87a6f422105dfa2d9dc1196e7d902b7d647e"},"properties":{"layerEntries":[{"sourceFiles":["/Users/dukenguyen/Products/oss/spring-boot-sample-undertow/target/classes/sample"],"extractionPath":"/app/classes/"}],"lastModifiedTime":1531987006884}}]}
  • /app/libs:
/app/libs # ls -al
total 14440
drwxr-xr-x    2 root     root          4096 Jul 19 07:57 .
drwxr-xr-x    1 root     root          4096 Jul 19 07:57 ..
-rw-r--r--    1 root     root         65100 Jan  1  1970 classmate-1.3.4.jar
-rw-r--r--    1 root     root        726778 Jan  1  1970 hibernate-validator-5.3.6.Final.jar
-rw-r--r--    1 root     root         55784 Jan  1  1970 jackson-annotations-2.8.0.jar
-rw-r--r--    1 root     root        282634 Jan  1  1970 jackson-core-2.8.10.jar
-rw-r--r--    1 root     root       1242948 Jan  1  1970 jackson-databind-2.8.10.jar
-rw-r--r--    1 root     root        224014 Jan  1  1970 javax.el-3.0.0.jar
-rw-r--r--    1 root     root         95806 Jan  1  1970 javax.servlet-api-3.1.0.jar
-rw-r--r--    1 root     root         19197 Jan  1  1970 jboss-annotations-api_1.2_spec-1.0.0.Final.jar
-rw-r--r--    1 root     root         66023 Jan  1  1970 jboss-logging-3.3.1.Final.jar
-rw-r--r--    1 root     root         42633 Jan  1  1970 jboss-websocket-api_1.1_spec-1.1.0.Final.jar
-rw-r--r--    1 root     root         16515 Jan  1  1970 jcl-over-slf4j-1.7.25.jar
-rw-r--r--    1 root     root          4596 Jan  1  1970 jul-to-slf4j-1.7.25.jar
-rw-r--r--    1 root     root         23645 Jan  1  1970 log4j-over-slf4j-1.7.25.jar
-rw-r--r--    1 root     root        309130 Jan  1  1970 logback-classic-1.1.11.jar
-rw-r--r--    1 root     root        475477 Jan  1  1970 logback-core-1.1.11.jar
-rw-r--r--    1 root     root         41203 Jan  1  1970 slf4j-api-1.7.25.jar
-rw-r--r--    1 root     root        273599 Jan  1  1970 snakeyaml-1.17.jar
-rw-r--r--    1 root     root        380409 Jan  1  1970 spring-aop-4.3.13.RELEASE.jar
-rw-r--r--    1 root     root        763281 Jan  1  1970 spring-beans-4.3.13.RELEASE.jar
-rw-r--r--    1 root     root        674197 Jan  1  1970 spring-boot-1.5.9.RELEASE.jar
-rw-r--r--    1 root     root       1070631 Jan  1  1970 spring-boot-autoconfigure-1.5.9.RELEASE.jar
-rw-r--r--    1 root     root          2290 Jan  1  1970 spring-boot-starter-1.5.9.RELEASE.jar
-rw-r--r--    1 root     root          2312 Jan  1  1970 spring-boot-starter-logging-1.5.9.RELEASE.jar
-rw-r--r--    1 root     root          2220 Jan  1  1970 spring-boot-starter-undertow-1.5.9.RELEASE.jar
-rw-r--r--    1 root     root          2348 Jan  1  1970 spring-boot-starter-web-1.5.9.RELEASE.jar
-rw-r--r--    1 root     root       1141639 Jan  1  1970 spring-context-4.3.13.RELEASE.jar
-rw-r--r--    1 root     root       1124388 Jan  1  1970 spring-core-4.3.13.RELEASE.jar
-rw-r--r--    1 root     root        263951 Jan  1  1970 spring-expression-4.3.13.RELEASE.jar
-rw-r--r--    1 root     root        825689 Jan  1  1970 spring-web-4.3.13.RELEASE.jar
-rw-r--r--    1 root     root        917856 Jan  1  1970 spring-webmvc-4.3.13.RELEASE.jar
-rw-r--r--    1 root     root       2180632 Jan  1  1970 undertow-core-1.4.21.Final.jar
-rw-r--r--    1 root     root        517900 Jan  1  1970 undertow-servlet-1.4.21.Final.jar
-rw-r--r--    1 root     root        167716 Jan  1  1970 undertow-websockets-jsr-1.4.21.Final.jar
-rw-r--r--    1 root     root         63777 Jan  1  1970 validation-api-1.1.0.Final.jar
-rw-r--r--    1 root     root        517653 Jan  1  1970 xnio-api-3.3.8.Final.jar
-rw-r--r--    1 root     root        116664 Jan  1  1970 xnio-nio-3.3.8.Final.jar

Thanks.

@d5nguyenvan
metadata-v2.json.zip

/app/libs/ In docker, I can't enter docker, it will report an error

Hi @qq12157138, I reviewed your metadata-v2.json file and saw that did not include the javax.servlet-api-*.jar file and that is the root cause of java.lang.ClassNotFoundException: javax.servlet.Filter. Do you have any either exclude statement in your pom.xml file to exclude the servlet-api or mark the servlet-api dependency as provided? Try to add the servlet-api dependency like this:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>compile</scope>
</dependency>

and check your metadata-v2.json include the javax.servlet-api-3.1.0.jar after build docker with jib.

Hope it can help!

@d5nguyenvan
I just switched from docker-maven-plugin to jib-maven-plugin, and my code has been running successfully before. Can you find out why this is so dependent on javax.servlet-api-3.1.0.jar? Is it because jib-maven-plugin is too intrusive?

I added javax.servlet-api-3.1.0.jar to my pom.xml. I checked the metadata-v2.json after compile jib:build and did not find servlet-api-3.1.0.jar.

Hi, @d5nguyenvan My project started successfully and I found the reason. If I don't add compile, javax.servlet-api-3.1.0.jar is not found in metadata-v2.json. After adding, I searched it in metadata-v2.json. I don't understand if this is a bug, because I have never added it before.

I set it to provided in my parent's pom.xml, but I am surprised that there is no problem in docker-maven-plugin.

In short, thank you

Hi @qq12157138, The reason is in your class the docker-maven-plugin depend on the spring-boot-maven-plugin and there are some differences in the dependencies processing between spring-boot-maven-plugin with jib-maven-plugin. I tested on spring-boot-maven-plugin by marking provided to java-servlet-api, however, when I run spring-boot:repackage the java-servlet-api still include in the final jar file, that is why the docker-maven-plugin run successfully.

@d5nguyenvan Thank you very much,I still have a small problem. I used to pack two versions at a time, 1.x and latest. How can I achieve this requirement when I use jib-maven-plugin? I don't want people who use my image to care about the version number, they just need to pull the latest version. However, I need to record the version number to use for the rollback operation.

@coollog How about the pack two versions at a time request? Do we have plan to support that feature?

@d5nguyenvan @qq12157138 you can run Jib twice to tag your image with different names: #654. Jib is optimized and will skip building images in this case.

@coollog looks like the "provided" dependency issue is not uncommon with Spring Boot-based WAR applications, e.g. #640. That makes sense, as a normal WAR expects that the Servlet APIs and a Servlet engine are provided and not part of the WAR.

@chanseokoh Thank for your information.
@qq12157138 You can run mvn twice with parameter -Dimage=your image to tag your image with different names.

@d5nguyenvan Thanks for diagnosing this issue thoroughly!
@chanseokoh I think we can consider providing some framework-specific integrations - and a detection of dependencies that are not provided and should be containerized can be a start

Closing this issue in favor of #675 - @qq12157138 feel free to reopen if there are any further issues.

Was this page helpful?
0 / 5 - 0 ratings