|
GettingStarted
Getting Started with JRuby on Google App Engine
Featured If you have issues please see the Google Group. Hello, WorldUse standard Ruby, the tools automatically use JRuby when necessary. # Install the google-appengine gem sudo gem install google-appengine bundle # Create a simple app appcfg.rb generate_app hello # Start development server dev_appserver.rb hello Building a guestbook using Sinatra# assign gems to your application cat >Gemfile <<EOF # Critical default settings: disable_system_gems disable_rubygems bundle_path ".gems/bundler_gems" # List gems to bundle here: gem "dm-appengine" gem "sinatra" EOF # Update config.ru to use Sinatra cat >config.ru <<EOF require 'guestbook' run Sinatra::Application EOF Now open a file called 'guestbook.rb' require 'sinatra'
require 'dm-core'
# Configure DataMapper to use the App Engine datastore
DataMapper.setup(:default, "appengine://auto")
# Create your model class
class Shout
include DataMapper::Resource
property :id, Serial
property :message, Text
end
# Make sure our template can use <%=h
helpers do
include Rack::Utils
alias_method :h, :escape_html
end
get '/' do
# Just list all the shouts
@shouts = Shout.all
erb :index
end
post '/' do
# Create a new shout and redirect back to the list.
shout = Shout.create(:message => params[:message])
redirect '/'
end
__END__
@@ index
<html>
<head>
<title>Shoutout!</title>
</head>
<body style="font-family: sans-serif;">
<h1>Shoutout!</h1>
<form method=post>
<textarea name="message" rows="3"></textarea>
<input type=submit value=Shout>
</form>
<% @shouts.each do |shout| %>
<p>Someone wrote, <q><%=h shout.message %></q></p>
<% end %>
<div style="position: absolute; bottom: 20px; right: 20px;">
<img src="/images/appengine.gif"></div>
</body>
</html>Uploading your app# Create an application-id at appspot.com: http://appengine.google.com/start/createapp # Replace the application-id in app.yaml application your-app-id # Upload to App Engine appcfg.rb update . # It should now be running at http://your-app-id.appspot.com |
► Sign in to add a comment
hey, i attended the JRuby on GAE today and i have a questions. Is it possible to use the user library within JRuby so I can easily login as administrator?
Do you mean the AppEngine? user API? The appengine-apis gem includes a JRuby version of the users API: http://appengine-jruby.googlecode.com/svn/trunk/rdoc/appengine-apis/classes/AppEngine/Users.html
FYI I had to change:
post '/' do
endto:
post '/post' do
endto get it working.
Sorry to be a pain, but this will work with Merb, right? Could we possibly have an example of a merb app?
I'm getting the following error:
My config.ru looks like this:
It does run on the appserver locally so not sure what wrecking the havoc...
Is there any reason to use these tools rather than other methods using Warble and so on? I do not see where this methods bundles gems to the lib and so on
This bundles your gems when you run appcfg.rb gem install ...
You can use warbler if you prefer, but this is currently the recommended way. For one thing this makes it much easier to test your app locally, since you don't have to bundle your app and run from a war file.
Two problems with this guide:
First, installing the google-appengine gem gives the error:
`C:\dev>gem install google-appengine Successfully installed google-appengine-0.0.1 1 gem installed Installing ri documentation for google-appengine-0.0.1... File not found: lib`
Does this error mean trouble? I have no idea.
Second, the appengine-rack example fails to mention that one must first do a
gem install appengine-rack
Platform: jruby 1.3.1 and Java 1.6.0_16-b01 64b installed and working on Vista 64.
Thanks for supporting ruby! I very much hope you get the chance to do a step-by-step, from-scratch walk through of getting jruby working with app engine.
The Hello World instructions were helpful, and aside from the need for appengine-rack, worked for me (maybe this should be set up as a gem dependency?)
A further howto on hooking this into Rails would be useful, but I suspect there will be a blog around somewhere which covers this.
I'm using JRuby 1.3.1 (brand new, clean) and am following the howto. I'm using AppEngine? SDK 1.2.2. I have it pointed to by the Google-recommended APPENGINE_HOME environment var.
After installing the Gems suggested in the how-to, when trying the Sinatra app demo (latest source code) via:
dev_appserver.rb .
I get the following error:
=> Booting DevAppServer? => Press Ctrl-C to shutdown server => Generating configuration files /Applications/Dev/jruby-1.3.1/lib/ruby/gems/1.8/gems/appengine-apis-0.0.8/lib/appengine-apis/datastore_types.rb:115:in `const_missing': cannot load Java class com.google.appengine.api.datastore.Key (NameError?)
So I started looking for this Key class. Indeed, it lives in appengine-api.jar, as I manually confirmed.
The rack demo works just fine, so I know the AppEngine? SDK is at least being found.
Any suggestions or locations to go for help?
References: http://groups.google.com/group/appengine-jruby/browse_thread/thread/715c1d5d783b1590 http://code.google.com/p/appengine-jruby/source/browse/appengine-sdk/appengine-sdk.erb?spec=svn1aed5074bc960fd3d1b524c1b6aea67472bd9348&r=1aed5074bc960fd3d1b524c1b6aea67472bd9348
Anyone have any info on how to use Google's URLFetch API from within JRuby?
Anyone have any info on how to use Google's URLFetch API from within JRuby?
require 'appengine-apis/urlfetch' Net::HTTP = AppEngine::URLFetch::HTTP hdoc = Net::HTTP.get(URI.parse("http://tumblr.com"))Aznaum, adding "require 'appengine-apis/urlfetch' yields:
$ dev_appserver.rb . => Booting DevAppServer? => Press Ctrl-C to shutdown server => Installing JRuby => Generating configuration files /usr/local/jruby-1.3.1/lib/ruby/site_ruby/1.8/builtin/javasupport/core_ext/object.rb:116:in `get_proxy_or_package_under_package': cannot load Java class com.google.appengine.api.urlfetch.URLFetchServiceFactory (NameError?)
@locke2053
Are you up to date with latest gem versions?
$ appcfg.rb gem list *** LOCAL GEMS *** addressable (2.1.0) appengine-apis (0.0.8) dm-appengine (0.0.3, 0.0.2) dm-core (0.10.0) extlib (0.9.13) maruku (0.6.0) rack (1.0.0) sinatra (0.9.4) syntax (1.0.0) $ appcfg.rb run -S irb irb(main):001:0> require 'myapp' => true irb(main):002:0> require 'appengine-apis/urlfetch' => false irb(main):003:0> Net::HTTP = AppEngine::URLFetch::HTTP (irb):4 warning: already initialized constant HTTP => Net::HTTP irb(main):004:0> hdoc = Net::HTTP.get(URI.parse("http://www.biblegateway.com/")) Aug 19, 2009 6:39:56 PM org.apache.commons.httpclient.HttpMethodBase getResponseBody WARNING: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended. => "<!DOCTYPE… irb(main):005:0>How does DataStore? work in development? I can't seem to save or query anything when running locally?
And where is the log file when running locally?
aznaum, I really think the appengine-apis gem is broken. I have tried this on multiple systems, some Windows, some Linux. Everything works fine unless I try to use appengine-apis. Perhaps you had to do something to make it work on your machine which isn't documented anywhere? Here's an example from a Windows XP 32 system:
C:\appengine>jruby -v jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.6.0_15) [x86-java] C:\appengine>appcfg.rb.bat gem list *** LOCAL GEMS *** addressable (2.1.0, 2.0.2) appengine-apis (0.0.8) appengine-jruby-jars (0.0.2) appengine-rack (0.0.2) appengine-sdk (1.2.2) appengine-tools (0.0.2) data_objects (0.9.12) dm-core (0.9.11) extlib (0.9.12) google-appengine (0.0.2) maruku (0.6.0) rack (1.0.0) sinatra (0.9.4) syntax (1.0.0) C:\appengine>type config.ru require 'appengine-rack' #require 'appengine-apis/urlfetch' AppEngine::Rack.configure_app( :application => "application-id", :version => 1) run lambda { Rack::Response.new("Hello World!") } C:\appengine>dev_appserver.rb.bat . => Booting DevAppServer => Press Ctrl-C to shutdown server => Installing JRuby => Retrieving jruby-rack => Installing appengine-sdk => Generating configuration files The server is running at http://localhost:8080/ ^C Terminate batch job (Y/N)? y [[[ here i uncomment the appengine-apis line ]]] C:\appengine>type config.ru require 'appengine-rack' require 'appengine-apis/urlfetch' AppEngine::Rack.configure_app( :application => "application-id", :version => 1) run lambda { Rack::Response.new("Hello World!") } C:\appengine>dev_appserver.rb.bat . => Booting DevAppServer => Press Ctrl-C to shutdown server => Generating configuration files C:/jruby-1.3.1/bin/../lib/ruby/1.8/rexml/encodings/UTF-8.rb:31:in `get_proxy_or_package_under_package': cannot load Ja va class com.google.appengine.api.urlfetch.FetchOptions (NameError) from C:/jruby-1.3.1/bin/../lib/ruby/site_ruby/1.8/builtin/javasupport/java.rb:51:in `method_missing' from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/appengine-apis-0.0.8/lib/appengine-apis/urlfetch.rb:34 from C:/jruby-1.3.1/lib/ruby/gems/1.8/gems/appengine-apis-0.0.8/lib/appengine-apis/urlfetch.rb:31:in `require' from C:/jruby-1.3.1/bin/../lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require' from config.ru:3:in `generate_xml'Are there specific versions of java or jruby that you are using? Did you have to set some environment variables? The fact that appengine-rack works but appengine-apis crashes makes me think my environment is set up properly.
When I run "dev_appserver.rb ." I receive the following error (see bottom for my system configuration):
JRuby limited openssl loaded. gem install jruby-openssl for full support. http://wiki.jruby.org/wiki/JRuby_Builtin_OpenSSL => Booting DevAppServer? => Press Ctrl-C to shutdown server => Installing JRuby => Retrieving jruby-rack => Installing appengine-sdk => Generating configuration files 2009-08-21 18:25:40.472 java[38102:80f] CocoaComponent compatibility mode?: Enabled 2009-08-21 18:25:40.473 java[38102:80f] CocoaComponent compatibility mode?: Setting timeout for SWT to 0.100000 Aug 22, 2009 1:26:57 AM com.google.appengine.tools.development.ApiProxyLocalImpl? log SEVERE: 1250904417044000? javax.servlet.ServletContext? log: Warning: error application could not be initialized org.jruby.rack.RackInitializationException?: Operation timed out
Caused by: org.jruby.exceptions.RaiseException?: Operation timed out
Aug 22, 2009 1:28:12 AM com.google.appengine.tools.development.ApiProxyLocalImpl? log SEVERE: 1250904492047000? javax.servlet.ServletContext? log: unable to create shared application instance org.jruby.rack.RackInitializationException?: Operation timed out
Caused by: org.jruby.exceptions.RaiseException?: Operation timed out
Aug 22, 2009 1:28:12 AM com.google.appengine.tools.development.ApiProxyLocalImpl? log SEVERE: 1250904492047000? javax.servlet.ServletContext? log: Error: application initialization failed org.jruby.rack.RackInitializationException?: unable to create shared application instance
Caused by: org.jruby.rack.RackInitializationException?: Operation timed outCaused by: org.jruby.exceptions.RaiseException?: Operation timed out
The server is running at http://localhost:8080/
MY SETUP: - Mac OS X 10.5.8 - jruby 1.3.1 (ruby 1.8.6p287) (2009-08-09 6586) (Java HotSpot?(TM) Client VM 1.5.0_19) [i386-java] - GEMS: actionmailer (2.3.3) actionpack (2.3.3) activerecord (2.3.3) activeresource (2.3.3) activesupport (2.3.3) addressable (2.1.0) appengine-apis (0.0.8) appengine-jruby-jars (0.0.2) appengine-rack (0.0.2) appengine-sdk (1.2.2) appengine-tools (0.0.2) extlib (0.9.13) google-appengine (0.0.2) rack (1.0.0) rails (2.3.3) rake (0.8.7) rspec (1.2.6) sources (0.0.1)
Any ideas about why this isn't working? On my other Mac with an identical setup, it works fine.
For anybody who is having problems with the Java SDK classes not being found (e.g. "cannot load Java class com.google.appengine.api.urlfetch.FetchOptions? (NameError?)", I worked around it by:
Adding $APPENGINE_HOME/lib/impl to the RUBYLIBS environmental variable Requiring the appengine jars in my sinatra app.rb, thus:
require 'appengine-api.jar' require 'appengine-api-stubs.jar' require 'appengine-local-runtime.jar'
(I suspect those three lines will need commenting before deploying...)
The first time I launched the app after that it failed, but a second time and it worked fine.
I also recommend anybody using Merb or Sinatra take a look at jruby-enginize, which generates GAE apps and provides rake tasks for bundling, running, deploying etc: http://github.com/ulbrich/jruby-enginize/tree/master (I'm not a contributor, just a happy user)
PS. Obviously APPENGINE_HOME is set to the base AppEngine? Java SDK directory...
If you're having trouble please use the appengine-jruby mailing list. It's very hard to keep track of the different conversations going on in these comments.
I have deployed my little app to appengine using jruby-appengine. Everything works as expected. Thank you developers!
i can run dev_appserver.rb as root on ubuntu linux but not as a user i seem to be getting permission errors. can anybody help ?
I am trying to create a sample with ramaze, but it look likes that this kind of file iteration does not work inside gems.jar
Find.find(File.expand_path('../snippets', FILE)) do |file|
endfounded in ramaze-2009.10/lib/ramaze/snippets.rb
How can I use a gem outside a jar?
@marcos.neves
I made a builder using the latest google-appengine & ramaze 2009.10. It's still pretty raw but builds perfect ramaze bundles that work.
http://gist.github.com/242123
Enjoy.
How can I use the Eclipse appengine plugin with this new JRuby+AppEngine? setup? I currently have an appengine project using JRuby in Eclipse by adding jars for Merb gems, JRuby, jruby-rack, and the appengine-jruby interface. How can I take this new google-appengine gem and make it work with my described setup?
Thanks! Amit
I found that bundler generate not correct load_path, so when you try start app he try load from '/bundler_gems' and cannot found it.
So, little patch will fix this little problem:
$LOAD_PATH << 'bundler_gems' puts require 'environment'
pftg.sof,
I am having the same issue as you. Where did you insert that line?
Does it works with rails too, other than sinatra?
For these two lines: disable_system_gems disable_rubygems
The latest bundler says disable_system_gems, disable_rubygems is removed. See the README for more information
For those, who get stuck on this on linux, put this in your .bashrc (located in home)
Does someone got it working using the new bundler?
I'm tried the grails on the appengine, but it simple does not work.. it works at the 1-2% of the hundreds refreshes, and has about 44431cpu_ms for every request in log.
The howto is missing the following line to work properly $ sudo gem install rack
always get this error in my mac OS X system
$ dev_appserver.rb . => Booting DevAppServer? => Press Ctrl-C to shutdown server 2010-05-11 10:04:42.292 java[3468:1707] CocoaComponent compatibility mode?: Enabled 2010-05-11 10:04:42.296 java[3468:1707] CocoaComponent compatibility mode?: Setting timeout for SWT to 0.100000 May 11, 2010 2:04:42 AM com.google.apphosting.utils.jetty.JettyLogger? info INFO: Logging to JettyLogger?(null) via com.google.apphosting.utils.jetty.JettyLogger? May 11, 2010 2:04:43 AM com.google.apphosting.utils.config.AppEngineWebXmlReader? readAppEngineWebXml INFO: Successfully processed /Users/eiffel/web/hello/WEB-INF/appengine-web.xml May 11, 2010 2:04:43 AM com.google.apphosting.utils.config.AbstractConfigXmlReader? readConfigXml INFO: Successfully processed /Users/eiffel/web/hello/WEB-INF/web.xml May 11, 2010 2:04:43 AM com.google.apphosting.utils.jetty.JettyLogger? info INFO: jetty-6.1.x May 11, 2010 2:04:43 AM com.google.appengine.tools.development.agent.impl.BlackList? initBlackList SEVERE: Unable to read a jre library while constructing the blacklist. Security restrictions may not be entirely emulated. /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/plugin.jar May 11, 2010 2:04:48 AM com.google.appengine.tools.development.ApiProxyLocalImpl? log SEVERE: 1273543488664000? javax.servlet.ServletContext? log: unable to create shared application instance org.jruby.rack.RackInitializationException?: no such file to load -- rubygems
nobody met this ?
I am getting the same error now, I am on a MAC too this stuff worked before
eiffelqiu & rsaccon: try to downgrade appengine-jruby-jars to (0.0.7).
If anyone is getting an error when doing the Getting Started tutorial like : "undefined method `configure_app' for AppEngine?::Rack:Module" You can do this to fix it.
You have to: - add yaml gem gem install haml
- create a app.yaml file example: application: kev1 version: 1 runtime: jruby
Uncomment/remove configure_app from config.ru #AppEngine?::Rack.configure_app( # :application => "kev1", # :version => 1)
This seems to be related to this update: http://jruby-appengine.blogspot.com/2010/06/google-app-engine-0014-gems-released.html
Cheers!
everything on this tutorial is still valid as of today. I am using linux and yes, "PATH=$PATH:/var/lib/gems/1.8/bin" is needed
Does not work with 1.9.2. I get this error using dev_appserver.rb as well as appcfg.rb:
=> Bundling gems ERROR: While executing gem ... (RuntimeError) can't add a new key into hash during iterationagree with MyAnLien?. it's not working with 1.9.2
Thanks! This works nicely with ruby 1.8.7 on Ubuntu 10.10.
Worked fine but seems a little slow. It takes like 2 seconds to post a shout. Local is very fast. Why that?
Any idea?
For some reason, appcfg.rb generate_app hello fails if you are doing it with Ruby 1.9.2.
Have to install 1.8.7 for it to work.
I was having the follow issue:
Feb 21, 2011 3:07:54 AM com.google.appengine.tools.development.ApiProxyLocalImpl? log SEVERE: javax.servlet.ServletContext? log: Application Error file:myapp/WEB-INF/lib/jruby-core-1.5.6.jar!/builtin/java/java.util.rb:52:in `each': illegal access on 'hasMoreElements': Reflection is not allowed on public boolean java.util.Collections$2.hasMoreElements() (TypeError?)
Feb 21, 2011 3:07:56 AM com.google.appengine.tools.development.ApiProxyLocalImpl? log SEVERE: javax.servlet.ServletContext? log: Error: Couldn't handle error file:myapp/WEB-INF/lib/jruby-core-1.5.6.jar!/builtin/java/java.util.rb:52:in `each': illegal access on 'hasMoreElements': Reflection is not allowed on public boolean java.util.Collections$2.hasMoreElements() (TypeError?)
Then, I uninstalled the recently published version of the appengine-sdk gem downgrading to the 1.4.0 version. The issue was solved. These were the commands:
sudo gem uninstall appengine-sdk -v "1.4.2"
sudo gem uninstall google-appengine -v "0.0.20"
sudo gem uninstall appengine-apis -v "0.0.23"
sudo gem install appengine-sdk -v "1.4.0"
sudo gem install google-appengine -v "0.0.19"
Apparently, the new version of appengine-sdk has some incompatibilities...
DON'T UPGRADE TO appengine-sdk 1.4.2 !!!!!!!!!!!!!!!!!!!
Seg fault.
previously I was using sdk 1.4.2 but as per @douglasm I downgraded to 1.4.0 and still no luck. same results.
Any thoughts?
Sam problem here...