[erlang-questions] Rebar & Cowboy on Windows 7
Mon Oct 8 17:54:15 CEST 2012
Having made the statement a few times over the last few months that Rebar is not compatible with Windows, I was challenged on this. My statement was based on my one-off experience with Rebar one or two years ago, so it was time I retried it. I decided to use the discussion about HTTP servers to try out Cowboy, which requires Rebar.
1. Rebar installed just fine on Windows. I downloaded the zip file from Git Hub and unzipped it into my Erlang lib directory. I ended up with a directory named “basho-rebar-32e67ef” in my lib, which is kind of nonstandard naming, but I could have renamed it to “rebar-...” if I had bothered to look up the correct version number to put there. Failing that, I could have just renamed it “rebar”, but it worked as it was, so I was unconcerned.
2. I ran the Rebar bootstrap.bat, which generated a rebar file and a rebar.cmd file to run it. So far I was quite encouraged, with the provision of a Windows “bat” file and now a “cmd” file. It would appear that Rebar was built to work on Windows. J
3. I downloaded Cowboy from Git Hub the same way I did Rebar. The resulting directory was again named “extend-cowboy-1f9d71c” in the nonstandard way of Git Hub, but it still works.
4. Here I ran into some problems, but it turned out they were mine rather than Windows’s. I tried a “rebar compile” on Cowboy, but got an error about the dependency on Ranch not being available. It should have been available, since I had previously downloaded it, and even if I hadn’t, the rebar.config told it where it could get it from. Turns out, however, that I have to explicitly tell it to get dependencies. Tuncer Ayaz – bless his soul – gave me a hand here and explained that I should use the command “rebar get-deps”, “rebar get-deps compile”, or abbreviated to “rebar g-d com”. With that, it downloaded Ranch and compiled fine. Yay!
5. Interestingly enough, Rebar does not download the dependencies into the Erlang lib directory, but rather into a “deps” subdirectory of your application. This means erl.exe and werl.exe cannot see it, but this can easily be rectified by either copying the downloaded applications up into the lib directory, or using the “-pa” option on the command line. If anyone has any suggestions as to which is better for their workflow, please let me know.
6. At this point, Cowboy was working, but I figured I should try to get it to do something useful. I couldn’t find a whole lot of documentation on its API, but I did find that it came with a few examples in the examples subdirectory. I decided to give the static example a whirl, and Rebarred it and then ran it, and it worked. Fine. Out of the box. Yay!
7. Unfortunately, when it served up the test.txt sample file, Chrome treated it as a download rather than text to be displayed in the browser. Usually when I encounter an issue where I want to see what’s coming down the wire, I just telnet to the appropriate port and send a “GET /” to see what is returned. I don’t think Cowboy handles HTTP 1.0, though I couldn’t find any record of that. At any rate, I just had to do some extra typing in order to send a minimal HTTP 1.1 request, and after some poking around, I discovered my problem was related to the MIME type being sent in the HTTP response. So I added the “mimetypes” application to the example’s Rebar dependencies, modified the static_app.erl file to use the function mimetypes:path_to_mimes to choose the correct MIME type and then restarted it – or at least tried to. Try as I may, I could not get it to work for the longest time. In the end, I determined that mimetypes’s lexer was built for Unix only, not Windows, so it was not recognizing the line endings in the provided mime.types file. The solution then was to modify mimetypes’s mimetypes_scan.xrl to recognize a CRLF as a newline, too. I suppose I should figure out how to use Git Hub so I can submit that patch. At any rate, now it all works like champ.
So I can confirm that both Rebar and Cowboy work on Windows 7 system. Thank-you all for your work on these.
Director, Technology & Research
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the erlang-questions