java - 在可执行 jar 中打包 spring 应用程序导致“无法读取架构文档”
问题描述
我已经使用以下 pom.xml/maven 配置将 spring 应用程序打包到可执行 jar 中
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
com.some.Main
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
现在,当我执行这个生成的 jar 时,它会给出以下警告
Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
并且执行失败并出现异常
Caused by: org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 70; cvc-elt.1.a: Cannot find the declaration of element 'beans:beans'.
同样的应用程序在 Eclipse 中没有 jar 打包运行时也能很好地执行。我确定这不是依赖问题,我提供了适当的依赖。由于包装成罐子而发生问题。请帮忙,谢谢你的时间。
解决方案
为什么要使用 spring-boot-maven-plugin 来构建 jar?下面是示例。
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass> com.some.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
推荐阅读
- javascript - 当滚动未完成时不要再次滚动事件
- python - Foobar - 测试用例未通过 - 无序逃脱
- r - R中的占位符
- asynchronous - 中间件转换为异步/等待
- javascript - 需要通过 UDP 将 ASCII 字符串从网站发送到 PC
- javascript - 如何使用 ES6 创建带有分组元素的表格
- reactjs - React Native TextInput 没有焦点方法
- git - git pull 返回“Already up-to-date”,但分支跟踪显示“local out of date”
- python - Numpy独特的功能
- json - Pandas DataFrame KeyError:1