简体   繁体   English

如何设置Maven源插件输出文件编码

[英]how to set maven source plugin output file encoding

using maven source plugin and upload source jar file successfully. 使用maven源插件并成功上传源jar文件。 while download maven sources from another computer and found source file chinese words messy.here is my build configuration in pom.xml: 当从另一台计算机下载maven源代码并找到源文件中文单词messy。这是我在pom.xml中的构建配置:

    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-source-plugin</artifactId>
    <version>2.1.2</version>
    <configuration><encoding>UTF-8</encoding>UTF-8<charset></charset></configuration>
    <executions>
    <execution>
<id>attach-sources></id>
<phase>jar</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
    </executions>
    </plugin>

you can use <encoding>UTF-8</encoding> with maven-resources-plugin 3.0.2 plugin, you can find code belop: 您可以将<encoding>UTF-8</encoding>maven-resources-plugin 3.0.2插件一起使用,可以找到代码belop:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.2</version>
        <configuration>
          ...
          <encoding>UTF-8</encoding>
          ...
        </configuration>
      </plugin>
    </plugins>
    ...
  </build>
  ...
</project>

and if you are using Maven 3.x then you useadd below code 如果您使用的是Maven 3.x,则使用下面的代码添加

<project>
  ...
  <build>

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

and Maven 2.x, use below property: 和Maven 2.x,请使用以下属性:

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

The only solution which is valid is this one: 唯一有效的解决方案是:

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

This solution is not related to Maven version (apart from that Maven 2 is end of life).. 该解决方案与Maven版本无关(除了Maven 2即将终止)。

This will set this property which is picked up by all apache maven plugins (maven-compiler-plugin,maven-resources-plugin etc.) which includes maven-sources-plugin. 这将设置此属性,该属性将由所有包含maven-sources-plugin的apache maven插件(maven-compiler-plugin,maven-resources-plugin等)使用。 But you should use most recent versions of the plugin and not such ancient version. 但是您应该使用该插件的最新版本,而不要使用较旧的版本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM