【问题标题】:Maven Jar Encoding ProblemMaven Jar 编码问题
【发布时间】:2010-11-19 13:05:47
【问题描述】:

如何指定(或“强制”)maven jar 插件以使用我的特定编码 (UTF-8)?

我的构建插件:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
 <execution>
  <phase>package</phase>
  <id>configurations-test</id>
  <goals>
   <goal>jar</goal>
  </goals>
  <configuration>
   <classesDirectory>target/test</classesDirectory>
   <forceCreation>true</forceCreation>
   <finalName>${artifactId}-test</finalName>
   </excludes>
  </configuration>
 </execution>
</executions></plugin>

我在父 pom 中设置了编码,每个副本都使用正确的编码执行

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

我在创建 Jar 之前控制了文件,这些文件格式正确。

注意,我做了很多尝试将特定编码添加到配置中,但仍然无法正常工作,在我打包的 Jars 中,我发现了格式不正确的字符(如 é,应该是 é)

解压后的文件(html、xml、属性等)包含诸如 é 而不是 é 之类的字符。

【问题讨论】:

  • 你是什么意思,你在你的罐子里找到了字符?在您的 jar 中的哪种文件中?一类? XML?财产? jar 文件的文件名?
  • 当我解压结果 jar 文件时,文件格式不正确。
  • 解压后的文件(html、xml、属性等)包含像é这样的字符而不是é

标签: plugins encoding utf-8 jar maven


【解决方案1】:

jar 不会弄乱您的文件。它只是复制字节。另一方面,资源插件可能。

您需要设置${project.build.sourceEncoding}

http://maven.apache.org/plugins/maven-resources-plugin/copy-resources-mojo.html

【讨论】:

  • ${project.build.sourceEncoding} 已设置。复制资源效果很好,文件格式正确。在我的示例中,进入目标/测试文件是正确的,但在结果 jar 中,压缩文件的格式错误
  • 知道了,似乎有些文件在存储库中仍被编码为 ISO-8859-1。我必须找到它们,将编码更改为 UTF-8,一切都会好起来的
  • 抱歉,我误认为该属性与您设置的属性不同,而不是相同。
【解决方案2】:

指定 UTF 编码属性:

<properties>
    <project.build.sourceEncoding>UTF</project.build.sourceEncoding>
</properties>

请注意,当我使用 UTF 编码部署到 wls 10.3.6 时,我遇到了以下错误,不确定其他人。

java.lang.UnsupportedOperationException:不支持的归档类型: zip:/oracle/fmwhome/user_projects/domains/dev_soa_osb/servers/AdminServer/tmp/_WL_user/myicarus-201609261658/131q4y/war/WEB-INF/lib/dummybean-spring-1.0.0.jar!/.

不确定如何配置 wls 以读取 utf zips

所以现在我使用 ASCII 作为编码,wls 不会抱怨

【讨论】:

    猜你喜欢
    • 2011-06-29
    • 2020-07-16
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多