如何在jar中配置maven:assembly根路径

时间:2020-12-08 23:56:21

Here is the pom.xml

这是pom.xml

<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>org.springframework.webflow</groupId>
    <artifactId>spring-js-resources-thin</artifactId>
    <version>2.2.1.RELEASE</version>
    <name>Spring js lib</name>
    <description>Spring javascript library without dojo</description>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/assembly.xml</descriptor>
                    </descriptors>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

and here is the assembly.xml

这是assembly.xml

<assembly>
    <id>js-jar</id>
    <formats>
        <format>jar</format>
    </formats>
    <fileSets>
        <fileSet>
            <directory>src/main/resources/</directory>  
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>META-INF/**/*</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

The problem is, everytime I open the generated jar file(spring-js-resources-thin-2.2.1.RELEASE-js-jar.jar), the root folder is always named as artifactid-version(spring-js-resources-thin-2.2.1.RELEASE), then the META-INF.

问题是,每当我打开生成的jar文件(spring-js-resources-thin-2.2.1.RELEASE-js-jar.jar)时,根文件夹总是命名为artifactid-version(spring-js-resources- thin-2.2.1.RELEASE),然后是META-INF。

I wonder there is anyway that I can build the jar file with the file name artifactid-version.jar, but WITHOUT the artifactid-version in the class path, just like every jar in the maven repository. I think there should be an option or a way to name the <outputDirectory>.

我想知道无论如何我都可以使用文件名artifactid-version.jar构建jar文件,但是在类路径中没有artifactid-version,就像maven存储库中的每个jar一样。我认为应该有一个选项或方法来命名

2 个解决方案

#1


42  

You have to tell maven-assembly-plugin not to include the base directory within the archive which can be achieved by using the following:

你必须告诉maven-assembly-plugin不要在归档中包含基本目录,这可以通过使用以下方法实现:

<assembly>
    <id>js-jar</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/resources/</directory>  
            <outputDirectory>.</outputDirectory>
            <includes>
                <include>META-INF/**/*</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

And the suggestion about using maven-jar-plugin is very good, cause it looks a little bit that you are misusing the maven-assembly-plugin.

关于使用maven-jar-plugin的建议是非常好的,因为它看起来有点你滥用maven-assembly-plugin。

In the most recent versions of maven-assembly-plugin you should . as the root folder. If you use / you will get a warning.

在最新版本的maven-assembly-plugin中你应该。作为根文件夹。如果您使用/,您将收到警告。

#2


3  

Add the element to the assembly like so.

像这样将元素添加到程序集。

<assembly>
    <id>js-jar</id>
    <formats>
        <format>jar</format>
    </formats>

    <baseDirectory>myBaseDir</baseDirectory>

    <fileSets>
        <fileSet>
            <directory>src/main/resources/</directory>  
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>META-INF/**/*</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

If you turn the <includeBaseDirectory> off then your archive won't have any root. So it depends on what you want. I prefer my zip files, for instance, to have a base directory so that it doesn't accidentally pollute a directory your in if you forget to create the dir and cd into it before unzipping. Much more convenient too.

如果关闭 ,那么您的存档将没有任何root。所以这取决于你想要什么。例如,我更喜欢我的zip文件有一个基本目录,这样如果你在解压缩之前忘记创建dir并cd进去,它就不会意外污染你的目录。更方便。

#1


42  

You have to tell maven-assembly-plugin not to include the base directory within the archive which can be achieved by using the following:

你必须告诉maven-assembly-plugin不要在归档中包含基本目录,这可以通过使用以下方法实现:

<assembly>
    <id>js-jar</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>src/main/resources/</directory>  
            <outputDirectory>.</outputDirectory>
            <includes>
                <include>META-INF/**/*</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

And the suggestion about using maven-jar-plugin is very good, cause it looks a little bit that you are misusing the maven-assembly-plugin.

关于使用maven-jar-plugin的建议是非常好的,因为它看起来有点你滥用maven-assembly-plugin。

In the most recent versions of maven-assembly-plugin you should . as the root folder. If you use / you will get a warning.

在最新版本的maven-assembly-plugin中你应该。作为根文件夹。如果您使用/,您将收到警告。

#2


3  

Add the element to the assembly like so.

像这样将元素添加到程序集。

<assembly>
    <id>js-jar</id>
    <formats>
        <format>jar</format>
    </formats>

    <baseDirectory>myBaseDir</baseDirectory>

    <fileSets>
        <fileSet>
            <directory>src/main/resources/</directory>  
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>META-INF/**/*</include>
            </includes>
        </fileSet>
    </fileSets>
</assembly>

If you turn the <includeBaseDirectory> off then your archive won't have any root. So it depends on what you want. I prefer my zip files, for instance, to have a base directory so that it doesn't accidentally pollute a directory your in if you forget to create the dir and cd into it before unzipping. Much more convenient too.

如果关闭 ,那么您的存档将没有任何root。所以这取决于你想要什么。例如,我更喜欢我的zip文件有一个基本目录,这样如果你在解压缩之前忘记创建dir并cd进去,它就不会意外污染你的目录。更方便。