Maven: How to configure native2ascii-maven-plugin

2020-08-10 07:20发布

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?

    <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!!

标签: java maven
6条回答
狗以群分
2楼-- · 2020-08-10 07:59

You need to define a execution section for every folder you want to process and move the src and dest to the execution part:

<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>
查看更多
不美不萌又怎样
3楼-- · 2020-08-10 07:59

Here is a sample configuration for version 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.

查看更多
等我变得足够好
4楼-- · 2020-08-10 08:01

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.

So I've solved the issue with two configuration:

  1. Set workDir to your project's target;
  2. 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>
    

I've used phase 'compile' since inside IDE is the one I use most.

查看更多
仙女界的扛把子
5楼-- · 2020-08-10 08:06

Here is a sample configuration for version 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>
查看更多
Fickle 薄情
6楼-- · 2020-08-10 08:10

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

I have to force someone to put it to official maven repositories ... but you can still use it in your own.

查看更多
太酷不给撩
7楼-- · 2020-08-10 08:21

Here a solution for "native2ascii". All files (recursively) found in src/main/locale are destined to 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>
            [...]
查看更多
登录 后发表回答