Maven在构建jar时破坏src / main / resources中的二进制文件 [英] Maven corrupting binary files in src/main/resources when building jar

查看:92
本文介绍了Maven在构建jar时破坏src / main / resources中的二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Maven项目中遇到了一个问题,该项目是我从src / main / resources / lib文件夹分发dll。

I've got an issue with a maven project where I am distributing dlls from the src/main/resources/lib folder.

该项目使用maven-assembly-plugin作为具有依赖项的单个jar构建。

The project is built as a single jar with dependencies using the maven-assembly-plugin.

不幸的是,maven进程在复制过程中损坏了我的dll库,因此它们不再对应用程序有用。

Unfortunately, the maven process is corrupting my dll libraries during the copy process so that they are no longer useful to the application.

我看过诸如资源过滤之类的概念。

I've had a look at such concepts as resource filtering.

这是我相关的pom.xml

Here's my relevant pom.xml

有人有什么想法吗?

我想我需要做这样的事情,但到目前为止,它对我来说不起作用。

I think I need to do something like this but so far it's not working for me.

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>

                    <resources>
                        <resource>
                            <directory>${basedir}/src/main/resources/lib</directory>
                            <filtering>false</filtering>
                        </resource>
                    </resources>

                    <archive>
                        <manifest>
                            <mainClass>de.bochumuniruhr.psy.bio.behaviourcoder.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>

我的最终解决方案(基于以下答案):

感谢您的出色回答。我最终得到了不需要扩展maven-resources-plugin的配置的答案。我将二进制文件放在需要过滤其他资源的 src / main / resources / unfiltered-resources 文件夹中。

Thank you for the great answers. I ended up going with the answer that doesn't require extending the configuration of the maven-resources-plugin. I placed my binary files in the src/main/resources/unfiltered-resources folder as I needed to filter my other resources.

此处是源代码的链接

下面是我在撰写本文时的最终工作pom。

Below is my final working pom at the time of writing.

<build>
        <finalName>BehaviourCoder_${git.build.time}_${git.commit.id.describe-short}</finalName>
        <resources>
            <resource>
                <directory>${basedir}/src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
            <resource>
                <directory>${basedir}/src/main/unfiltered-resources</directory>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>pl.project13.maven</groupId>
                <artifactId>git-commit-id-plugin</artifactId>
                <version>2.2.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>revision</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <generateGitPropertiesFile>true</generateGitPropertiesFile>
                    <injectAllReactorProjects>true</injectAllReactorProjects>
                    <dateFormat>yyyy-MM-dd_HHmmss</dateFormat>
                    <dateFormatTimeZone>UTC</dateFormatTimeZone>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>de.bochumuniruhr.psy.bio.behaviourcoder.Main</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>


推荐答案

此部分:

                <resources>
                    <resource>
                        <directory>${basedir}/src/main/resources/lib</directory>
                        <filtering>false</filtering>
                    </resource>
                </resources>

应该在< build /> 部分,例如:

 <project>
      <build>
          <resources>
              <resource>
                  <directory>${basedir}/src/main/resources/lib</directory>
                  <filtering>false</filtering>
              </resource>
          </resources>
          <plugins>
              ...
          </plugins>
      </build>
 </project>

这篇关于Maven在构建jar时破坏src / main / resources中的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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