我有一个 Maven/Spring Boot 项目和资源文件夹,其中混合了带有拉丁字符和非拉丁字符的文件。
这是我的 pom.xml:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
<artifactId>example</artifactId>
<groupId>com.example</groupId>
<version>0.0.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>api</artifactId>
<packaging>war</packaging>
<properties>
<java.source.version>1.8</java.source.version>
<java.target.version>1.8</java.target.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding
</properties>
<build>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src/test/resources</directory>
<filtering>true</filtering>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>false</addResources>
<jvmArguments>
-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005
</jvmArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>${java.source.version}</source>
<target>${java.target.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
<useDefaultDelimiters>true</useDefaultDelimiters>
</configuration>
</plugin>
</plugins>
</build>
</project>
现在,在 Maven 构建(在 Jenkins 上)后的 Linux 计算机上,生成的 war 文件内的资源文件夹仅包含名称仅包含拉丁字符的文件。所有文件名包含非拉丁字符的文件都不存在。
我做错了什么以及如何告诉 Maven 将所有文件放在那里?顺便说一句 - 在 Windows 机器上一切正常
已更新
另外,我已经更新了我的 Jenkins,现在所有文件都在我的 war 文件中。但现在我有另一个问题 - 解压缩(war 文件)后文件名中的所有非拉丁字符看起来像 ??????
看起来 Jenkins/Maven 构建由于某种原因杀死了文件名。如何解决?
这是一个示例 war 文件,其中包含 Unicode 文件名:war file在 Linux 机器上解压后看起来像 ??????
最佳答案
对 pom.xml
的以下更改对我有帮助:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<junitArtifactName>junit:junit</junitArtifactName>
<encoding>UTF-8</encoding>
<inputEncoding>UTF-8</inputEncoding>
<outputEncoding>UTF-8</outputEncoding>
<argLine>-Xms256m -Xmx512m -XX:MaxPermSize=128m -ea -Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
</plugins>
</build>
关于java - Maven项目和名称中带有unicode字符的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44335941/