我正在使用 maven 程序集来打包一个可执行 jar 及其依赖项和资源。资源(spring 应用程序上下文)从 jar 中排除。当我运行mvn assembly:assembly
时,测试运行并且构建成功。但是,当我在程序集打包后运行可执行 jar 时,我得到FileNotFoundException
. 找到打包下\lib
的spring框架等依赖。资源my-application-context.xml
文件也打包在\lib
. 你能帮忙吗?
这是POM:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.2</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
<excludes>
<exclude>*.xml</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<excludes>
<exclude>**/*.xml</exclude>
</excludes>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.myapp.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
和描述符:
<formats>
<format>zip</format>
</formats>
<files>
<file>
<source>${project.basedir}/src/main/resources/my-application-context.xml</source>
<outputDirectory>lib</outputDirectory>
</file>
</files>
<dependencySets>
<dependencySet>
<useProjectArtifact>false</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.scriptSourceDirectory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.bat</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*.jar</include>
</includes>
</fileSet>
</fileSets>