由于NoClassDefFoundError,无法启动嵌入式容器

时间:2017-01-17 12:53:50

标签: java maven docker spring-boot dockerfile

我的SpringBoot应用程序适用于Eclipse IDE,但是当我在Docker Container上运行我的应用程序时,它的图像构建良好,但是当我运行图像时,它将获得异常ClassDefnotfound并且无法启动嵌入式容器。

 How can I fix it?`

In Dockerfile
FROM java:8
EXPOSE 8080
ADD /target/docker.ras.jar docker.ras.jar
RUN sh -c 'touch /docker.ras.jar
ENTRYPOINT ["java","-jar","docker.ras.jar"]

    In pom.xml i also use maven plugin 
    <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>

  <groupId>example.docker.ras</groupId>
  <artifactId>docker.ras</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
      <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>1.4.3.RELEASE</version>
      </parent>
  <name>docker.ras</name>
  <url>http://maven.apache.org</url>
  <properties>

  <java.version>1.8</java.version>
  <start-class>docker.ras.App</start-class>
  <docker.image.prefix>springio</docker.image.prefix>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>

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

        </dependency>
      <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <version>1.3.0.RELEASE</version>
          </dependency>


        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>compile</scope>
    </dependency>
    <dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-core</artifactId>
    </dependency>
    <dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
</dependency>

 <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>

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

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>

  <plugins>
          <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
          <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
      </plugin>

      <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>0.4.11</version>
            <configuration>
                <imageName>${docker.image.prefix}/${project.artifactId}</imageName>
                <dockerDirectory>src/main/docker</dockerDirectory>
                <resources>
                    <resource>
                        <targetPath>/</targetPath>
                        <directory>${project.build.directory}</directory>
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>
  </plugins>

  <finalName>docker.ras</finalName>
  </build>
  </project>

My Error Stack trace

2 个答案:

答案 0 :(得分:0)

检查Docker Container中的Java版本。 希望你在工件后运行应用程序。 如果是这样,请确保它正在添加所有依赖项。

答案 1 :(得分:0)

这可能是您在部署中包含服务器特定的API,或者您的servlet API版本错误。我怀疑前者。

如果你正在使用maven检查你的servlet api有一个在pom中提供的范围。

另见

http://tomcat.apache.org/whichversion.html