问题
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).
I tried
java -jar GV_S.war -S rake db_migrate[1]
with 1 being the version but this didn't work.
this gave me :
[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
Any help 'll be appreciated
-Thanks
回答1:
this seems not yet supported by warbler - executing jruby style commads works with an executable .jar but making a .war executable only allows it to run with an embed web server ... nothing else.
回答2:
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)
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]
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>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>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]
should work
来源:https://stackoverflow.com/questions/9839319/running-rake-task-from-within-war-file