java - Maven 在构建 jar 时损坏 src/main/resources 中的二进制文件

标签 java maven dll

我从 src/main/resources/lib 文件夹分发 dll 的 maven 项目出现问题。

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

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

我看过资源过滤等概念。

这是我的相关 pom.xml

有人有什么想法吗?

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

            <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 文件夹中,因为我需要过滤我的其他资源。

这是 source code 的链接.

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

<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>

关于java - Maven 在构建 jar 时损坏 src/main/resources 中的二进制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46734985/

相关文章:

java - 确实需要在 appEngine 中上传文件

java - urlconnection 不读取内容长度

c++ - 使用 C++ 代码从 FORTRAN DLL 调用函数

delphi - 使用 dll 中的函数

c++ - PATH 环境变量没有影响? (VS2010)

java - Java MySQL 连接器中的 DELETE 语句有任何已知问题吗?

java - 计算战斗系统的暴击率

java - 运行 Spring Boot 应用程序时出现兼容版本问题,但在 pom 中只有版本

java - 使用 Jenkins 跟踪其他版本的更改

java - gwt-maven-插件 : webapp structure