java Maven:如何配置native2ascii-maven-plugin
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7105039/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven: How to configure native2ascii-maven-plugin
提问by user829237
Im firing this question at you guys since the project-page itself has not a lot of information.
Basicly im setting up the native2ascii-maven-plugin to process some of my resources. It works fine for processing the files in root directory. But now i have files under subdirectory: /template/email/
and would like them to be included in the processing. Can you guys please help me out?
我向你们提出这个问题,因为项目页面本身没有很多信息。基本上我正在设置 native2ascii-maven-plugin 来处理我的一些资源。它适用于处理根目录中的文件。但是现在我在子目录下有文件:/template/email/
并且希望它们包含在处理中。你们能帮我吗?
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native2ascii-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<configuration>
<dest>target/resources</dest>
<src>src/main/resources</src>
</configuration>
<executions>
<execution>
<id>native2ascii-utf8</id>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<encoding>UTF8</encoding>
<includes>ApplicationResources*.properties, errors.properties, /template/email/newBooking*.ftl</includes>
</configuration>
</execution>
</executions>
</plugin>
Thanks a bunch!!
谢谢一堆!!
采纳答案by Tobias Schulte
You need to define a execution section for every folder you want to process and move the src and dest to the execution part:
您需要为每个要处理的文件夹定义一个执行部分,并将 src 和 dest 移动到执行部分:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native2ascii-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<id>native2ascii-utf8-resources</id>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<dest>target/resources</dest>
<src>src/main/resources</src>
<encoding>UTF8</encoding>
<includes>ApplicationResources*.properties, errors.properties, /template/email/newBooking*.ftl</includes>
</configuration>
</execution>
<execution>
<id>native2ascii-utf8-email</id>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<dest>target/resources/email</dest>
<src>src/main/templates/email</src>
<encoding>UTF8</encoding>
</configuration>
</execution>
</executions>
</plugin>
回答by Fred
Here a solution for "native2ascii". All files (recursively) found in src/main/locale
are destined to target/classes
:
这是“native2ascii”的解决方案。在src/main/locale
中找到的所有文件(递归)都注定target/classes
:
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native2ascii-maven-plugin</artifactId>
<version>1.0-alpha-1</version>
<executions>
<execution>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<encoding>UTF8</encoding>
<src>src/main/locale</src>
<dest>target/classes</dest>
</configuration>
</execution>
</executions>
</plugin>
[...]
回答by user3399000
Here is a sample configuration for version 1.0-beta-1:
以下是 1.0-beta-1 版本的示例配置:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native2ascii-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<id>native2ascii-utf8-resources</id>
<phase>process-classes</phase>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<workDir>src/main/resources</workDir>
<encoding>UTF8</encoding>
<tempDir>${basedir}/temp</tempDir>
<includes>
<include>**/*_fa.properties</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
In case of error, you can check the plugin source code here.
如果出现错误,您可以在此处查看插件源代码。
回答by Miller Cy Chan
Here is a sample configuration for version 2.0+
这是 2.0+ 版本的示例配置
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>native2ascii-maven-plugin</artifactId>
<version>2.0.1</version>
<executions>
<execution>
<id>native2ascii-utf8-properties</id>
<phase>process-resources</phase>
<goals>
<goal>inplace</goal>
</goals>
<configuration>
<dir>${project.build.directory}/classes</dir>
<includes>**/*.properties</includes>
<encoding>UTF-8</encoding>
</configuration>
</execution>
</executions>
</plugin>
回答by Reginaldo Santos
The drawback in 1.0-beta-1 is the approach with workDir. I don't wanna change my source code in each build, but I still need some tool to provide unicode anotation to my property files.
1.0-beta-1 的缺点是workDir的方法。我不想在每个构建中更改我的源代码,但我仍然需要一些工具来为我的属性文件提供 unicode 注释。
So I've solved the issue with two configuration:
所以我用两种配置解决了这个问题:
- Set workDir to your project's target;
Change the phase to something after process-resources;
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>native2ascii-maven-plugin</artifactId> <version>1.0-beta-1</version> <executions> <execution> <id>native2ascii-utf8-i18n</id> <phase>compile</phase> <goals> <goal>native2ascii</goal> </goals> <configuration> <workDir>target/classes/i18n</workDir> <encoding>${project.build.sourceEncoding}</encoding> <includes> <include>**/*.properties</include> </includes> </configuration> </execution> </executions> </plugin>
- 将 workDir 设置为您项目的目标;
将阶段更改为流程资源之后的某事;
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>native2ascii-maven-plugin</artifactId> <version>1.0-beta-1</version> <executions> <execution> <id>native2ascii-utf8-i18n</id> <phase>compile</phase> <goals> <goal>native2ascii</goal> </goals> <configuration> <workDir>target/classes/i18n</workDir> <encoding>${project.build.sourceEncoding}</encoding> <includes> <include>**/*.properties</include> </includes> </configuration> </execution> </executions> </plugin>
I've used phase 'compile' since inside IDE is the one I use most.
我使用了“编译”阶段,因为在 IDE 中是我使用最多的阶段。
回答by dmatej
I have recently created another version of native2ascii maven plugin, that covers usage of both old versions and also contains XML files used by m2e Eclipse plugin: https://github.com/dmatej/native2ascii/releases
我最近创建了另一个版本的 native2ascii maven 插件,它涵盖了旧版本的使用,还包含 m2e Eclipse 插件使用的 XML 文件:https: //github.com/dmatej/native2ascii/releases
I have to force someone to put it to official maven repositories ... but you can still use it in your own.
我不得不强迫某人把它放到官方的 Maven 存储库中……但你仍然可以在你自己的仓库中使用它。