从 war 文件中运行 rake 任务 [英] Running rake task from within war file

查看:20
本文介绍了从 war 文件中运行 rake 任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码库最初是用 ruby​​ 编写的.它有一个 rakefile.rb 文件来执行数据库迁移.后来我把整个东西都改成了 jruby,以便于部署,效果很好.我面临的唯一问题是如何运行我的 rake 任务(执行数据库迁移).

My code base initially was written in ruby. It had a rakefile.rb file to perform db migration. I later changed the whole thing to jruby for the ease of deployment which works fine. Only problem I am facing is how to run my rake task (to perform db migrations).

我试过了

java -jar GV_S.war -S rake db_migrate[1]

1 是版本,但这不起作用.

with 1 being the version but this didn't work.

这给了我:

[Winstone 2012/03/23 18:04:56] - Beginning extraction from war file
[Winstone 2012/03/23 18:04:56] - WARNING: The Servlet 2.4/2.5 spec XSD was unavailable inside the winstone classpath. Will be retrieved from the web if required (slow)
[Winstone 2012/03/23 18:04:56] - No webapp classes folder found - /tmp/winstone6913591014121608835webroot/GV_S.war/WEB-INF/classes
[webapp 2012/03/23 18:04:57] - jruby 1.6.7 (ruby-1.9.2-p312) (2012-02-22 3e82bc8) (Java HotSpot(TM) 64-Bit Server VM 1.6.0_26) [linux-amd64-java]
[Winstone 2012/03/23 18:05:03] - Listener winstone.ajp13.Ajp13Listener not found / disabled - ignoring
[Winstone 2012/03/23 18:05:03] - Listener winstone.ssl.HttpsListener not found / disabled - ignoring
[Winstone 2012/03/23 18:05:03] - Winstone Servlet Engine v0.9.10 running: controlPort=disabled
[Winstone 2012/03/23 18:05:03] - HTTP Listener started: port=8080

任何帮助将不胜感激

-谢谢

推荐答案

终于找到了有用的东西....我第一次尝试

Finally found something that works.... i first tried

java -jar lib/jruby-complete-1.6.7.jar -S rake db_migrate[1] 

在我的个人机器上运行良好,但在生产中给了我类似下面的消息

which was working fine on my personal machine but giving me something like the message below on production

rake aborted!
cannot load Java class com.mysql.jdbc.Driver

Tasks: TOP => db_migrate
(See full trace by running task with --trace)

这是因为我在我的 rake 任务中使用了像 sequel、logger 等 gem ........ 所以我将 rake 任务所需的 gem 安装在一个单独的目录中并将其转换为 jar 文件(http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar)...这个命令终于奏效了...

this was because i was using gems like sequel, logger etc inside my rake task.... i head those installed on my machine but not on production machine.... installing those gems on production was not an option.... so i installed the gems required in the rake task in a separate directory and converted it into a jar file( http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar)... this command finally worked...

java -jar lib/jruby-complete-1.6.7.jar -rlib/mygems.jar -S rake db_migrate[1]

请注意:无论您将 jar 文件放在何处,warbler 都会始终将其发送到 lib 目录,尽管您仍会在原始位置看到一个虚拟 jar 文件...我认为如果通过几种方式解决该解决方案可能会更整洁,虽然还没有尝试过......

point to note: no matter where you place the jar file, warbler 'll always send this to lib directory although you 'll still see a dummy jar file at the original location... i think the solution can be a bit neater if worked out in a couple of ways, although haven't tried this....

i>通过将 gem 文件包含在 jruby-complete-1.6.7.jar 本身中,如上面提到的博客中所述...

i>by including the gem files in jruby-complete-1.6.7.jar itself as mentioned in the blog mentioned above...

java -jar lib/jruby-complete-1.6.7.jar -S rake db_migrate[1]

然后应该工作......

should work then...

ii>通过编写某种清单文件并将其包含在 mygems.jar 中以使其独立运行...如果发生这种情况

ii>by writing some kind of a manifest file and include it in the mygems.jar to make this run independently... if this happens

java -jar myapp.jar -S rake db_migrate[1] 

应该工作

这篇关于从 war 文件中运行 rake 任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆