通过maven-assembly-plugin包装在jar中包含spring xml [英] Include spring xml in jar by maven-assembly-plugin packaging

查看:165
本文介绍了通过maven-assembly-plugin包装在jar中包含spring xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用spring的配置xml文件创建一个包含所有依赖项的可执行jar。

I am trying to create an executable jar with all of its dependency along with the spring's configuration xml file.

这是maven-assembly-plugin的定义在pom.xml中:

Here is the definition of the maven-assembly-plugin in the pom.xml:

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>service.coucou.Main</mainClass>
            </manifest>
        </archive>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
        <descriptors>
                     <descriptor>assembly.xml</descriptor>
                 </descriptors>
    </configuration>
</plugin>

这是assembly.xml:

This is the assembly.xml:

<?xml version="1.0" encoding="UTF-8"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>jar-with-dependencies</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <useProjectArtifact>true</useProjectArtifact>
            <unpack>true</unpack>
            <scope>runtime</scope>
        </dependencySet>
    </dependencySets>
    <fileSets>
        <fileSet>
            <includes>
                <include>/src/main/resources/cxf.xml</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

我试图包含 /src/main/resources/cxf.xml 创建jar中的文件。但它不包括xml。如何将它包含在jar中?

I am trying to include /src/main/resources/cxf.xml file in the created jar. But it is not including the xml. How can I include it in the jar?

推荐答案

替换< fileSets /> with:

<fileSet>
  <directory>${basedir}/src/main/resources</directory>
  <includes>
    <include>cxf.xml</include>
  </includes>
</fileSet>

这篇关于通过maven-assembly-plugin包装在jar中包含spring xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆