我有一个Spring启动应用程序可以通过IntelliJ的Spring Boot运行配置以及mvn spring-boot:run
运行良好,但是,当我尝试通过mvn package
打包时,我收到以下错误从java -jar application.jar
java.io.IOException:无法打开嵌套的jar文件 ' LIB /弹簧引导起动的Web-1.3.3.RELEASE.jar' 在org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:349) 在org.springframework.boot.loader.archive.JarFileArchive.getNestedArchive(JarFileArchive.java:112) 在org.springframework.boot.loader.archive.JarFileArchive.getNestedArchives(JarFileArchive.java:96) 在org.springframework.boot.loader.ExecutableArchiveLauncher.getClassPathArchives(ExecutableArchiveLauncher.java:75) 在org.springframework.boot.loader.Launcher.launch(Launcher.java:60) 在org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52)
引起: java.io.IOException:无法找到ZIP中心目录 读取2227字节后的记录 在org.springframework.boot.loader.jar.CentralDirectoryEndRecord。(CentralDirectoryEndRecord.java:64) 在org.springframework.boot.loader.jar.JarFile。(JarFile.java:118) 在org.springframework.boot.loader.jar.JarFile.createJarFileFromFileEntry(JarFile.java:387) 在org.springframework.boot.loader.jar.JarFile.createJarFileFromEntry(JarFile.java:357) 在org.springframework.boot.loader.jar.JarFile.getNestedJarFile(JarFile.java:343) ......还有5个
此似乎与java.io.IOException when running Spring Boot jar on Centos 6.4 / Open JDK 1.7.0类似,但解决方案是删除与TLD库相关的损坏的jar文件,该问题没有引用哪个嵌套jar无法解决加载(因此我不确定它是否完全相同)。我尝试删除并重新创建~/.m2/repository
目录无济于事。我也尝试过不同版本的Spring Boot(因为我之前从未遇到过这个问题)但没有运气。
我的pom文件在下面。
<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>com.oranization</groupId>
<artifactId>application</artifactId>
<version>1.0-SNAPSHOT</version>
<!--Spring-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<properties>
<slf4j.version>1.7.12</slf4j.version>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>2.0.8.RELEASE</version>
</dependency>
<!--Spring-->
<!--Logging-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!--Logging-->
<!--Database-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.35</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time-hibernate</artifactId>
<version>1.4</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jadira.usertype</groupId>
<artifactId>usertype.core</artifactId>
<version>3.2.0.GA</version>
</dependency>
<dependency>
<groupId>com.jolbox</groupId>
<artifactId>bonecp-spring</artifactId>
<version>0.8.0.RELEASE</version>
</dependency>
<!--Database-->
<!--Joda Time-->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.8.1</version>
</dependency>
<!--Joda Time-->
<!--Test-->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.0.14-beta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.3.2</version>
<scope>test</scope>
</dependency>
<!--Test-->
<!--Web Support-->
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.4.6</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.6.0</version>
</dependency>
<!--Web Support-->
<!--Utils-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-services</artifactId>
<version>0.1.7</version>
</dependency>
<dependency>
<groupId>de.danielbechler</groupId>
<artifactId>java-object-diff</artifactId>
<version>0.93.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.2</version>
</dependency>
<!--Utils-->
<!--Reactor-->
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-bus</artifactId>
<version>2.0.7.RELEASE</version>
</dependency>
<!--Reactor-->
<!--Swagger-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.3.0</version>
</dependency>
<!--Swagger-->
<!--Elasticsearch-->
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>2.1.1</version>
</dependency>
<!-- AWS -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.9.33</version>
</dependency>
<!--PDF processing-->
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>1.8.11</version>
</dependency>
<!--PDF processing-->
<!--Doc/Docx file processing-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.13</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.13</version>
</dependency>
<!--Doc/Docx file processing-->
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
</dependencies>
<build>
<finalName>application</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<!-- Copy Dockerfile -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/
</outputDirectory>
<resources>
<resource>
<directory>src/main/docker</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>zip-files</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<zip destfile="${basedir}/target/app.zip"
basedir="${basedir}/target"
includes="Dockerfile, Dockerrun.aws.json, application.jar"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
修改
删除Finder中的~/m2/repository
目录并清空废纸篓后,我从Intellij进行了重新导入,然后从Maven Projects菜单中进行了package
。尝试使用java -jar target/application.jar
运行最终产品时出现新错误:
线程中的异常&#34; main&#34; java.lang.IllegalStateException: java.io.IOException:无法读取字节 在org.springframework.boot.loader.ExecutableArchiveLauncher。(ExecutableArchiveLauncher.java:53) 在org.springframework.boot.loader.ExecutableArchiveLauncher。(ExecutableArchiveLauncher.java:45) 在org.springframework.boot.loader.JarLauncher。(JarLauncher.java:34) 在org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:52) 引起:java.io.IOException:无法读取字节 在org.springframework.boot.loader.jar.Bytes.get(Bytes.java:53) 在org.springframework.boot.loader.jar.JarEntryData。(JarEntryData.java:70) 在org.springframework.boot.loader.jar.JarEntryData.fromInputStream(JarEntryData.java:212) 在org.springframework.boot.loader.jar.JarFile.loadJarEntries(JarFile.java:155) 在org.springframework.boot.loader.jar.JarFile。(JarFile.java:122) 在org.springframework.boot.loader.jar.JarFile。(JarFile.java:104) 在org.springframework.boot.loader.jar.JarFile。(JarFile.java:95) 在org.springframework.boot.loader.archive.JarFileArchive。(JarFileArchive.java:65) 在org.springframework.boot.loader.archive.JarFileArchive。(JarFileArchive.java:61) 在org.springframework.boot.loader.Launcher.createArchive(Launcher.java:152) 在org.springframework.boot.loader.ExecutableArchiveLauncher。(ExecutableArchiveLauncher.java:50) ......还有3个
答案 0 :(得分:2)
原来这与this question有关。尽管Java 8可能支持大量文件,但我的jar文件中大约有77k(由于我的React前端包含了node_modules
目录),当我正确配置了排除过滤器时,它就像一个魅力。
故事的道德,达到最大文件限制将导致奇怪的事情发生。