Windows line endings: Exception in thread 'main' java.io.FileNotFoundException /opt/app/config.yml{caret}M (no such file or directory)
As I mentioned in my previous post we’ve been making it possible to deploy our application to a new environment and as part of this we defined an upstart script which would run the JAR.
We tend to edit code on Windows and then test it out on the vagrant VM afterwards.
The end of our upstart script looked a bit like this:
script
cd /opt/app
java -jar /opt/app/app.jar /opt/app/config.yml
end script
Unfortunately when we tried to launch the application using 'start app' we got this error:
Exception in thread "main" java.io.FileNotFoundException /opt/app/config.yml^M (no such file or directory)
We were trying to load the configuration file in the program which was failing because of the Windows line ending just after the file name. That was being read in as part of our config file name argument.
I tried change the upstart script to have the name in quotes (which in hindsight makes no sense) but that made no difference but eventually I realised we could make the file have UNIX line endings and solve our problem.
Using notepad++:
Edit > EOL Conversions > Unix Format
And all was well with the world.
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.