Passing line.separator to maven

2019-07-13 19:25发布

问题:

I would like to pass line.separator to exec plugin but it seems that I do not correctly passing it. I have tried many combinations but could not find the solution. What is the correct way?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <phase>test</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>java</executable>
               <arguments>
                   <argument>-Dline.separator=\n</argument>
                   <argument>-classpath</argument>
                   <classpath />
                   <argument>GeneratorExec</argument>
               </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>

回答1:

That is not going to work. The problem is that the command is executed in a shell. The shell will interpret the \n as two characters, not one escaped.

Look at this blog: Passing '\n' (new-line) on command line in Java.

You will have to let the GeneratorExec take the two characters as an argument and then handle it in the program.