November 16, 2012

Getting Started with Cloud Foundry for Java and Spring Developers

I received the following (very awesome) e-mail the other day:


I have been watching a couple of your videos on YouTube, and I have some questions that are decidedly remedial, which I recognize, but i am also having trouble getting answer to them.

I am not a developer - I have managed a bunch of Wordpress sites, and have built 8-10 sites with Dreamweaver, leveraging CSS and basic functionality. I understand the basics of HTML web development, and have even built a .NET application using Visual Studio. But I am not a developer - you could call me a hobbyist and have some nominal experience around building websites using HTML and Dreamweaver.

However, I am running into more and more situations where knowing how to write real web applications will be beneficial... I have installed the latest rev of STS, signed up for CloudFoundry, even configured the micro cloud on my macbook.... but now I don't know how to get started! what do I do? how do I build a database (vPostgres, MySQL, I don't care), and connect to it with a web application? I can't seem to find the tutorials that are remedial enough for me.

Any suggestions?
Thanks, Josh -...

A few points: he is referring to the SpringSourceDev YouTube channel, where I have a few videos (and where you can find a slew of content from other great presenters on all things SpringSource). Additionally, I omitted his name from this email.

So, what we have here is an essentially tech-minded, but not particularly advanced, developer looking to take the plunge into the wide world of web development, and he wants to get started with Cloud Foundry. This is an awesome (and increasingly common) occurence. Cloud Foundry gives an outlet to all the people and departments that want to get things on the web and in production quickly. The cloud is an important next step, not only for the hard core developers out there, but also for the infinite many that need technology in place, quickly, and can't or won't wait for IT to deliver it. This happens a lot with what Patrick Chanezon and others refer to as situational applications.

I've updated and included my initial response to him below in the hopes that it will help others.

You say remedial like it's a bad thing! We all get started at some point.

Cloud Foundry is a good way to get started (and continue to mastery!) with web development.

An important tool is the vmc command line tool. vmc is the simplest way to get started with this stuff. Setup vmc and interact with the command line and understand the tool's capabilities. Here are some docs on getting started with vmc and the vmc tunnel. If you have questions don't hesitate to reach out to me. Once you've got vmc and the tunnel installed, there's a lot you can do!

If you're doing Java development, specifically, then the SpringSource Tool Suite (STS) is a huge start. STS is a free, Eclipse-based distribution. It is a super set of the Java EE distribution of Eclipse, and includes a slew of handy plugins pre-installed, including Maven support. Maven is a tool that lets you easily compile your code. While you can install STS's plugins on top of an existing Eclipse distribution, you won't get the Maven support, and that's required for this tutorial.

Cloud Foundry lets you run and manage web applications. You don't need to worry about the hard disk, servers, databases, RAM, etc. However, the compromise is that you can only run well known application stacks. Cloud supports Java (including Spring applications, and anything else you might want to run on a command line or inside of Tomcat 6), Ruby, Node.js, and Scala. Other ecosystem partners have taken the code and run their own version of Cloud Foundry, and often include extra features. For example, AppFog has support for Python and PHP, above and beyond what Cloud Foundry offers. Tier3 and Uhuru both support .NET on their derivatives. So, what type of language will you use? I've written the following assuming you're going to use Spring and Java, a very common combination.

To make sure that everything is easy to find in STS for this tutorial, use the Window -> Reset Perspective command.

If you're using STS (which is an Eclipse -based distribution) you'll need to install the Cloud Foundry WTP (web tools project) connector. Go to the Help -> Eclipse Marketplace. Search for "CloudFoundry" and you'll find the "Cloud Foundry integration for Eclipse." Install it if you haven't already.

Once installation finishes, right click on the white space in your Servers panel, and choose New Server.

Then choose VMWare -> Cloud Foundry.

Click Next on the first screen (there's no need to change anything there.) and then enter your credentials to log in to the cloud.

You can verify your credentials by clicking Validate Account. Then, click Finish.

Once installed, you can double click on the Cloud Foundry server to see what's going on in your account, just as you would from the vmc command line tool. The tab that presents itself can take up some serious screen real estate, so you might close the Spring Explorer, Outline, and Task List panels, as I have. The Cloud Foundry tab has two sub tabs at the bottom: one called Overview, and another called Applications. You can click on an application to see the resources provisioned for the application, including which services (databases, message queues, etc) have been apportioned for it and how much RAM and CPU the application is taking.

To create an application, go to the File menu, choose New -> Spring Template Project.

Then choose Spring MVC project and click Next.

It might ask you to download a few kilobytes to get the tutorial if you haven't already downloaded this before. If so, click Yes.

Then fill in an application name and a top-level package. The wizard requires 3 tokens in the top-level package name, so com.joshlong.cloudfoundrydemo would work, but com.joshlong won't.

Once you have an application, it's easy enough to deploy it to Cloud Foundry. Simply drag the project from the Project panel onto the Cloud Foundry server in the Servers panel. It'll ask you to specify information about the application: what runtime, what language, etc. The defaults are good enough in this case, so just leave them as-is and click Next.

Next, you'll be asked to specify the URL for the application as well as how much memory to allocate. Again, the defaults are fine in this case.

The application will deploy, and - if you open the URL given in a browser window - you'll be greeted with a new application on Cloud Foundry!

Getting started with programming Spring is another story for another blog post at least! In the meantime, you might checkout the Green Beans blogs on

I hope this post has been helpful. If not, always feel free to reach me at my email.