英文:
Packaging spring application in executable jar causes 'Failed to read schema document'
问题
我已将Spring应用程序打包成可执行的JAR,以下是相应的pom.xml/Maven配置:
<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打包时,同样的应用程序可以正常执行。我确信这不是依赖问题,我已经提供了适当的依赖项。问题是由于打包成JAR文件导致的。请帮忙解决,非常感谢您的时间。
英文:
I have packaged a spring application into executable jar with following pom.xml/maven configuration
<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>
Now when I execute this generated jar it gives following WARN
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>.
and execution fails with exception
Caused by: org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 70; cvc-elt.1.a: Cannot find the declaration of element 'beans:beans'.
And same application executes well when run without jar packaging in eclipse. I am sure it is not dependency issue, I have provided appropriate dependencies.
Issue happens due to packaging into jar.
Please help, thanks for you time.
答案1
得分: 1
为什么要使用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>
英文:
Why do you use spring-boot-maven-plugin to build jar? The below is sample.
<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>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论