是否可以通过 Rake 运行 Ruby 项目?
我有一个使用 NetBeans 启动的 Ruby 项目,因此已生成 Rake 文件。有没有办法可以通过命令行运行项目?
当我通过 NetBeans 使用 F6 时,它运行良好,就像我使用 Alt+F6 的自动化测试套件一样。我本质上是在寻找类似...
$ rake run
这存在吗?
I've got a Ruby project started with NetBeans, so the Rake file has been generated. Is there a way that I can run the project over the command line?
It runs fine when I use F6 through NetBeans, as does my automated test suite with Alt+F6. I'm essentially looking for something like...
$ rake run
Does this exist?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ruby 编程的目标(通常)是编写一个 Web 应用程序,或者编写一个可以从命令行运行的程序。
对于 Web 应用程序,
rake run
选项可能是值得的,但实际上最常见的 Web 应用程序框架是 Rails,对于 Rails,您可以只需运行一个专用的网络服务器,使用script/server
运行您的网络应用程序。对于命令行程序,只需运行您打算作为主文件的 ruby 文件(包含在启动时运行的代码的文件)。 Ruby 没有 Java 所面临的任何困难(例如,拥有一个具有正确
Main-class
属性的 jar 文件,以及获取正确的类路径,等等)。因此,您实际上并不需要 rake run 目标,因为 rakefile 中不需要隐藏任何复杂性。The goal of ruby programming is (generally) to either write a web application, or write a program that can be run from the command line.
For a web application a
rake run
option might be worthwhile, but really the most common web applicaition framework is Rails, and for rails, you can just run a dedicated webserver running your web app withscript/server
.For a commandline program, just run whichever ruby file you have intended as the main file (the one with the code that runs at startup). Ruby doesn't have any of the difficulties that Java does (e.g. having a jar file with the right
Main-class
attribute, and getting the classpath right, etc...). So you don't really need arake run
target, because there's no complexity that needs to be hidden in the rakefile.尽管 Ken 是对的,但您当然可以创建一个 rake 任务来运行您的程序。在 lib/tasks/project.rake: 中
,然后
rake project:run
将执行您想要的操作。Although Ken's right, you can certainly make a rake task to run your program. In lib/tasks/project.rake:
and then
rake project:run
will do what you want.