3

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>
Peter Mularien
  • 2,578
  • 1
  • 25
  • 34
Cemo
  • 5,370
  • 10
  • 50
  • 82

1 Answers1

3

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.

maba
  • 47,113
  • 10
  • 108
  • 118
  • 1
    Seems strange. When I pass parameter at command line as `-Dline.separator=$'\n'` with cygwin. its working... Why? – Cemo Nov 08 '12 at 13:42
  • Maybe exec plugin is calling cmd instead of bash? – Cemo Nov 08 '12 at 13:43
  • It is actually bash that translates $'\n' to the correct control character 0x0A that will be accepted by java on the command line. It will only work in bash though. – stenix Mar 31 '15 at 13:55