2

我有一个 Maven/Java 应用程序。部分应用程序允许您下载一些文件。这是项目设置。

+src
    +main
        +resources
            +downloads
                MyDocument.docx
            jdbc.properties
pom.xml

jdbc.properties当其中包含硬编码值时,下载工作正常。但是,我正在尝试更新应用程序以使用 Maven 配置文件并为不同的环境指定不同的数据库连接。我设法让它与以下内容一起工作pom.xml

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

但是,即使该jdbc.properties文件使用正确的环境数据库信息正确填充,下载功能也会停止工作。该文件将被下载,但当您尝试打开它时,它会显示The file MyDocument.docx cannot be opened because there are problems with the contents..

我尝试更改<directory>tosrc/main/resources/*.properties并添加一个附加<resource>项,我<filtering>src/main/resources/downloads. 但两种方法都没有奏效。如何防止 Maven 过滤损坏文件?

仅供参考 - 我查看了 WAR 内部文件,也无法从那里打开文件(它们已经损坏)。

4

1 回答 1

2

更新:来自https://stackoverflow.com/a/10025058/516167的更好解决方案

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <version>2.5</version>
  <configuration>
    <encoding>UTF-8</encoding>
    <nonFilteredFileExtensions>
      <nonFilteredFileExtension>xls</nonFilteredFileExtension>
    </nonFilteredFileExtensions>
  </configuration>
</plugin>

您应该从过滤中排除MyDocument.docx (*.docs) 等文件。

<build>
   <resources>
      <resource>
        <directory>src/main/resouces</directory>
        <filtering>true</filtering>
        <excludes>
          <exclude>**/*.docx</exclude>
        </excludes>
      </resource>
    </resources>
</build>

或为下载定义备用目录,例如:

<build>
   <resources>
      <resource>
        <directory>src/main/downloads</directory>
      </resource>
    </resources>
</build>
于 2013-03-17T10:24:59.797 回答