Java

The java service can host any kind of application based on java.servlet.

This makes it suitable not only fore “barebones” servlets, but also for a lot of frameworks and languages, including (but not limited to):

  • Clojure,
  • Grails,
  • JRuby on Rails,
  • Lift,
  • Play!,
  • Scala,
  • and a lot more!

Most ready-to-use applications will also run fine. You can generally assume that if it ships as a WAR [1] file, it will run on DotCloud.

Basic Use

Let’s assume that you are building a DotCloud application called “ramen”. For the sake of simplicity, we will also assume that everything related to this application is located in a directory called “ramen-on-dotcloud”.

Let’s setup our environment:

$ dotcloud create ramen
Created application "ramen"
$ mkdir ramen-on-dotcloud

A DotCloud application is described by a Build Files, which is a simple YAML file named “dotcloud.yml” located in our “ramen-on-dotcloud” directory. To add a new service to our app, we just add the following lines to “ramen-on-dotcloud/dotcloud.yml”:

www:
  type: java
  approot: hellojava

This Build File tells the DotCloud platform that the code (or the WAR file) for this service will be located in the hellojava directory.

If you are not deploying multiple services, you can omit the approot directive, and put your WAR files in the same directory as dotcloud.yml.

After copying your WAR file into the ramen-on-dotcloud directory, your app is ready.

We can now push our application to DotCloud:

$ dotcloud push ramen ramen-on-dotcloud/
# upload /home/.../ramen-on-dotcloud/ ssh://dotcloud@uploader.dotcloud.com:21122/ramen
# rsync
[...]
sent 8.11K bytes  received 352 bytes  995.06 bytes/sec
total size is 14.78K  speedup is 1.75
Deployment for "ramen" triggered. Will be available in a few seconds.
2011-06-28 04:27:34 [api] Waiting for the build. (It may take a few minutes)
2011-06-28 04:27:48 [www.0] service booted
2011-06-28 04:27:48 [www.0] The build started
2011-06-28 04:27:48 [www.0] Fetched code revision rsync-1309235251.44
2011-06-28 04:27:51 [www.0] Reloading nginx configuration: nginx.
2011-06-28 04:27:51 [www.0] The build finished successfully
2011-06-28 04:27:51 [api] Deploy finished

Deployment finished successfully. Your application is available at the following URLs
www: http://d07c100d.dotcloud.com/

A random URL has been generated for each web service in your application (it won’t be http://d07c100d.dotcloud.com/ for your app, but something else). Point your browser to this URL to see your new service in action!

If you want to attach a better URL to your application, read the Custom Domains documentation.

Internals

The java servlet is served by Jetty. For most purposes, it will be 100% compatible with other application servers like Tomcat.

If you upload a WAR file named thing.war, it will come up as http://...dotcloud.com/thing/. To host your application directly at the top of the URL hierarchy, name it ROOT.war.

If you push an unpacked WAR, and want to host it at the root of your service, you should place your code (i.e. the WEB-INF directory and everything) in a directory called ROOT.

Note that while you can push your apps as unpacked WAR files, it is not recommended to do so, since some class loading mechanisms work better when your app ships as a WAR file.

[1]http://en.wikipedia.org/wiki/Web_application_archive