Convert files to UNIX format using Maven

Dan Polites picture Dan Polites · Jan 29, 2010 · Viewed 20.5k times · Source

I have an application that is developed in a Windows environment. The application itself gets deployed to a Linux environment. Each time I deploy this application I have to convert executable files to UNIX format using dos2unix. I originally thought this was caused by the Windows CP1252 encoding, so I updated Maven to encode the files to UTF-8. This didn't solve my issue and I quickly found out that this has to do with carriage returns and line feeds by searching this site. Is there a way to have Maven convert all of the files to UNIX format during the build process? I am using Maven 2.2.1 and Java 5.

Answer

Pascal Thivent picture Pascal Thivent · Jan 29, 2010

The assembly plugin has a lineEnding option which can be used to control the line-ending of the files for a given fileSet. This parameter is precisely there to do what you want. Ultimately, you could build zip archives with with CRLF lines and tar.gz archives with LF lines.

E.g.

...
<fileSet>
    <directory>${basedir}/src/main/build/QA</directory>
    <outputDirectory>/bin</outputDirectory>
    <includes>
        <include>start.sh</include>
    </includes>
    <lineEnding>unix</lineEnding>
</fileSet>
...

Possible values at this time include:

  • "keep" - Preserve all line endings
  • "unix" - Use Unix-style line endings (i.e. "\n")
  • "lf" - Use a single line-feed line endings (i.e. "\n")
  • "dos" - Use DOS-/Windows-style line endings (i.e. "\r\n")
  • "windows" - Use DOS-/Windows-style line endings (i.e. "\r\n")
  • "crlf" - Use carriage-return, line-feed line endings (i.e. "\r\n")