We removed our free Sandbox April 25th.
You can read more on our blog.

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" using the flavor "sandbox" (Use for development, free and unlimited apps. DO NOT use for production.)
$ 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://ramen-dotcloud.dotcloud.com/

URLs have been generated for each web service in your application from your application an account names. Open your browser to see your new service in action!

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

Advanced Configuration

You can modify some advanced parameters of the MongoDB configuration from your “dotcloud.yml”:

www:
  type: java
  config:
    java_initial_heap_size: 64
    java_maximum_heap_size: 128
    java_maximum_permgen_size: 64
    jetty_version: jetty-6
    java_version: java-6

Let’s see what each setting does:

  • java_initial_heap_size: this option controls the initial size (in megabytes) of the memory allocation pool of the JVM;
  • java_maximum_heap_size: this option controls the maximum size of the memory allocation pool of the JVM (keep in mind that this is not changed when you vertically scale);
  • java_maximum_permgen_size: this option controls the maximum size of the memory pool allocated by the JVM to store class files, you might need to change this for large applications;
  • jetty_version: this option lets you specify which jetty version you want to use. Options are jetty-6, jetty-7, and jetty-8. Default is jetty-6;
  • java_version: this option controls which java version you will be using with this service. Options are java-6, and java-7. Default is java-6. java-7 only works with the following jetty_version‘s jetty-7 and jetty-8.

New settings are applied on the next push.

Java and Jetty Versions

The java service lets you decide which java and jetty versions you want to use with your application. It currently supports Java 1.6, and Java 1.7. It also supports Jetty 6, 7 and 8.

Note

Java 1.7 only works with Jetty 7 and 8. The default settings are Java 1.6 and Jetty 6. To learn how to configure these options, see the the Advanced Configuration section.

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