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

查看:234
本文介绍了Maven在构建jar时破坏source / 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

有没有人有任何想法?

Does anyone have any ideas?

我想我需要做这样的事情,但到目前为止它并不适合我。

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.

以下是源代码。

以下是我撰写本文时的最终工作资料。

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时破坏source / main / resources中的二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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