MIGRATING GOOGLE APP ENGINE ECLIPSE PROJECT TO NETBEANS
Hi dear readers. In this blog I describe in details the steps you need to follow to:
i. Install and configure Google App Engine on Netbeans
ii.Setup and Deploy the sample guestbook app
iii.Migrate an existing Eclipse Google App Engine App to Netbeans and then deploy
Premises:
The instructions here might have a conversational kind of style, hardly formatted (created it first as a word document), and also might be “served” elementary as I was walking a none too techy friend through the process. Also, should I admit that having a tool (investigating ant) to perform this steps would be more succinct.
Now that that’s out of the way, BELOW is the steps you need to perform. “topriddy” here refers to an imaginary project folder. Enjoy and comment.
MIGRATING GOOGLE APP ENGINE ECLIPSE PROJECT TO NETBEANS
A. Installation of Google App Engine on Netbeans
Works with Netbeans 6.9 or Netbeans 7.0
- Download and Install Netbeans 7.0 or Netbeans 6.9 if not already done. Link Here: http://download.netbeans.org/netbeans/7.0/final/bundles/netbeans-7.0-ml-windows.exe
- Launch Netbeans IDE
-
Install Google App Engine Plugin:
- Go To Tools > Plugins > Settings and the click Add.
- When prompted enter Name: App Engine. URL: http://kenai.com/downloads/nbappengine/NetBeans69/updates.xml
- Switch to Available Plugins Tab, and hit the Reload Catalog button.
- Choose/Select Google App Engine modules (server, configuration, deployment, editor hints),
- Click Install Button
B. Create and Deploy Test App On Google App Engine
The below steps specify how you can deploy test GuestBook App sample on GAE from Netbeans:
- Launch Netbeans if not already launched
- Select File > New Project > Samples > Google App Engine > Guest Book
- Click Next > Next…> Finish (leave defaults)
- Select the newly created project under your projects View
-
Go to Web Pages > WEB-INF > appengine-web.xml to configure app specific settings.
- Here you might want to set the application name to name of project you created on your Google App Engine Online Account
-
At this point you can right click project and either :
- Click Deploy to test on local computer server
- Or Click on Deploy to Google App Engine to deploy to live GAE Server. You would be prompted to enter account details, i.e email and password
C. Migrate an Existing Project to Run with Netbeans IDE.
Case in Focus: topriddy application
The following group of files are what is necessary to be in place:
- Java Source Files usually located in $workspace/$projectname/src
- Web Files (css, javascript, images etc): located in $workspace/$projectname/war (N.B: Exempt the WEB-INF folder from this list).
- The configuration files: appengine-web.xml and web.xml located in: in $workspace/$projectname/war/WEB-INF
- The library files usually “jars” located in: $workspace/$projectname/war/WEB-INF/lib (N.B: Exempt all the jar files that start with appengine*, google*, and datanucleus* from this list)
Now that the above is understood, I would now walk you through the process of migrating an existing GAE project in Eclipse to Netbeans.
Steps:
- Download or Identify Eclipse GAE Project: E.g topriddy
- Launch Netbeans and create “that first sample project” if you haven’t already done so. (Steps described in Section B)
- Launch “Windows Explorer”, look for the sample guestbook project and duplicate it.
- Rename duplicated guestbook folder to your desired name. Say topriddy-netbeans
-
To copy Java source files:
- Delete all files located in Netbeans project : …/NetBeansProjects\topriddy\src\java
- Copy src files from eclipse project here $workspace/topriddy/src and dump in above (i.e …/NetBeansProjects\topriddy\src\java)
- Done
-
To copy web files/artifacts:
- Delete all files located in Netbeans project folder: …\topriddy\web
- Copy ALL files from Eclipse Project $workspace/topriddy/war/ to …/NetBeansProjects\topriddy\web (N.B: Remember to exempt the WEB-INF folder here)
- done.
-
To Copy Config Files: appengine-web.xml and web.xml
- Locate Eclipse project config files in: $workspace\topriddy\war\WEB-INF
- Locate directory to copy to in netbeans project here: …/NetBeansProjects \topriddy\web
- If not already created, create Folder WEB-INF (case sensitive) in path mention in b. above.
-
To Copy Libraries from Eclipse project to Netbeans Project,
- Navigate to Netbeans Project Folder and create a “lib” directory in …/NetBeansProjects \topriddy\web\WEB-INF
- Copy all jars (except the already identified exemptied ones ) from the eclipse base: : $workspace\topriddy\war\WEB-INF\lib\ to the netbeans lib path: …/NetBeansProjects \topriddy\web\WEB-INF\lib
-
To Install Libs in Netbeans Project
- Launch Netbeans and open Netbeans project if not already opened
- Right Click Libraries under your project, select Add Jar/Folder
- On prompt of File Select Dialog, Navigate to your project directory and go to the lib path, copy all jars therein
- Select Okay. Then you;re done
- Confirm that the appengine-web.xml is set to the GAE Project you previously created with Google App Engine Account.
- Right Click and Deploy as mentioned previously
Jambito…A mobile site for checking jamb result online
Jambito is a simple light-weight mobile site for checking jamb result online. It is done as an open source project and codebase is available on github repos here.
The main idea behind this project is to provide candidates with an alternative means to check their jamb results. Much as I don’t intend for this to be a release document ( i do intend writing a real blog post after “rush hour”), I would try as much as possible to summarize the intended goals.
“Ambitious” goals of the project
1. To provide a lighter mobile and web means for candidate to check their results online
2. To allow candidates check their result online for an unlimited number of times by caching data.
3. To allow for result to be sent to candidate as an email (in progress)
As seen above, the goals of the project are quite simple. I for one, do not like that the current jamb site is somewhat buggy (unavailable resources in code), input text fields doesn’t work on my favourite browser amongst others.
In a following blog post, i would talk about the technologies used (Java, Apache Wicket, Google App Engine, Objectify, HtmlUnit, etc) and at least provide an educational basis for beginners to learn from sample codes.
So there goes Jambito mobile site.
[i should thank @jeberulz for providing freely a logo which i am yet to integrate to the app but is available in the git repos.]
[I should also mention that this is work in progress, hence improvements, bug reports, etc is welcome from the open source community]
[N.B: app can be tested using the testdata regnos: 7373744888AE]
Quick Sip of CoffeeScript
Err…another blog so soon already you might say. Well, blame it on the caffeine.
This is just going to be a “quickie” on some cool stuff i came across. Am not by no means a javascript guru, save for a few alert() here and there cant remember writing much js till jquery came along to make life easier for us all. Also, I had the luxury on using my current favourite Java web framework Apache Wicket which still lets you do cool js stuff without actually writing any JS yourself.
Okay, back to the Coffee and scripting. This is how http://coffescript.org defines itself:
CoffeeScript is a little language that compiles into JavaScript. Underneath all those awkward braces and semicolons, JavaScript has always had a gorgeous object model at its heart. CoffeeScript is an attempt to expose the good parts of JavaScript in a simple way.
The golden rule of CoffeeScript is: “It’s just JavaScript”. The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime. You can use any existing JavaScript library seamlessly from CoffeeScript (and vice-versa). The compiled output is readable and pretty-printed, passes through JavaScript Lint without warnings, will work in every JavaScript implementation, and tends to run as fast or faster than the equivalent handwritten JavaScript.
Basically, its just saying its making you write javascript in another language that compiles down to js much more easily. As someone, who is a java developer but has been recently marveled and also taking a peek into dynamic programming languages – Python, Ruby and err…Clojure (still trying to wrap my head around the parenthesis, funny i had to put this in brackets – no pun intended). I find it interesting to write js without much need for braces.
Coffescript really is a light language that makes it so natural for you to get coding and up to speed in no time if you already know javascript or know how to program in any other language. I must add that just 10 minutes look at the language already got me feeling I knew enough(…to walk on hot stones without actually getting burnt).
So enough of the its cool talk lets see some codes…Meanwhile you can of course check the one page tutorial on the site later on. (Its so simple it requires just less than one page to learn).
Below, I now show codes of one of the most frequently method i learnt in school and I believe must have implemented in all the languages I have studied.
Code 1: Find the sum of two numbers
sum = (a, b) -> a + b
alert "Sum of numbers is: " + sum (6,9)
Code 2: Find the sum of n numbers
sum = (numbers...) ->
total = 0
total += nos for nos in numbers
return total
alert "The sum is: " + sum(3,2,1)
Code 3: Find the factorial of N
factorial = (n) -> return 0 if n < 0 return 1 if n == 0 or n == 1 return n * factorial(n - 1) alert "5! = " + factorial 5
And that’s it. The sweetest part of all this is that you can easily run and test these codes in your browser using the “Try Coffescript” menu available on www.coffescript.org.
And at this point I drop my cup of coffee, get back to my day’s job, and look into a wonderful weekend. Cheers all.
How to generate Emails, SMS, and other Messages from Templates in Java
Hi readers…been a while since I last posted. So I have been obsessed with message generation over the past few days. I couldn’t bear the current method we used in generation of messages so I decided I would finally get to examining the available template generators in Java and then see how I could tap into it. So this blog post would be about generate messages from template files.
To make this a easy read(not sure how I can make it shorter though), I would like we define our problem statement. Say we were designing a class to send a welcome message to new users on our website. We would have the following requirements then:
Problem Statement: Design a class that generates a SMS & Email welcome message for a new user registration given user phone number and names (lastname and firstname).
We are also given a format on how we want the message to look like below
Message Format
Hello Chuck Norris, You are welcome to www.glory-love.com. Your registration with 08032057172 has been processed.
So say given this requirement, for us to understand and appreciate the problem we are about to solve, I’ll show the traditional way probably common too.
Traditional Method I – Crude
public String getRegistrationMail(String lastName, String firstName, String phoneNumber){
StringBuilder builder = new StringBuilder();
builder.append("Hello ").append(lastName).append(" ").append(firstName).append(",\n");
builder.append("You are welcome to www.glory-love.com. Your registration with ");
builder.append(phoneNumber).append(" has been processed.");
return builder.toString();
}
Traditional Method II
public String getRegistrationMail(String lastName, String firstName, String phoneNumber){
final String template = "Hello %s %s, \n You are welcome to www.glory-love.com. Your registration with %s has been processed";
String msg = String.format(template, lastName, firstName, phoneNumber);
return msg;
}
The Suggested Way – Using Template Generators
The traditional methods above here aren’t half as flexible or even efficient. Also, it would be more ideal if we could separate the template generic logic from our codes.
Numerous template generators exist in the java world, and I currently have a preference for StringTemplate, Apache Velocity and FreeMaker. The basic idea of these template generators are the same. You create a template file, instantiate a generation engine, and then pass in the parameters to it. For the purpose of this blog, I would show how it can be done using either of StringTemplate or Apache Velocity.
Modern Solution using StringTemplate
First the template – registration.stl
Dear $lastName$ $firstName$, You are welcome to www.glory-love.com. Your registration with $phoneNumber$ has been processed.
public String getRegistrationMail(String lastName, String firstName, String phoneNumber) {
String templateMessage = IOUtils.readLines(this.getClass().getResourceAsStream("registration.stl"));
StringTemplate template = new StringTemplate(templateMessage);
Map params = new HashMap();
params.put("phoneNumber", phoneNumber);
params.put("lastName", lastName);
params.put("firstName", firstName);
template.setAttributes(params);
return template.toString();
}
Modern Solution II – Using Velocity Engine
Velocity Template File – registration.vsl
Dear $lastName $firstName, You are welcome to www.glory-love.com. Your registration with $phoneNumber has been processed.
public String getRegistrationMail2(String lastName, String firstName, String phoneNumber) {
Properties props = new Properties();
props.put("resource.loader", "class");
props.put("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
VelocityEngine ve = new VelocityEngine();
ve.init(props);
Map params = new HashMap();
params.put("lastName",lastName );
params.put("firstName", firstName);
params.put("phoneNumber", phoneNumber);
Template t = ve.getTemplate("/registration.vsl");
VelocityContext context = new VelocityContext(params);
StringWriter writer = new StringWriter();
t.merge(context, writer);
return writer.toString();
}
Conclusions
Wheeeww!! So that’s it basically. The above shows how to work with templates, generation, etc from Java. StringTemplate, FreeMarker, and Apache Velocity are very interesting technologies and I do advise you spend time taking a look at them.
Intelligent DropDown Choice Implementation in Wicket
This blog entry is going to be about showing how to implement a dropdown choice in Apache Wicket, which is currently my favourite java web framework. Specifically, I would be showing off an example of a web page with two drop down choices, where the selection in the first drop down choice determines the available options in the other drop down choice. Dropdown choice is also known as combo box in some quarters.
Before I delve into code, I would like to give a good example of a popular use-case for the above. Imagine a drop down choice of countries where the user chooses a country first then chooses a State afterwards. We all can agree that the list of states shown to the user at any point in time would of course be dependent on the current country selected. Illustrated below:

For the purpose of this example and for simplicity, I would be showing two drop down boxes. The first drop down box shows a category that can be any of {“Even”, or “Odd”}. Depending on the category selected, the Number combo is populated with either a set of even numbers or odd numbers. This is shown below:

Now some codes:
First the html: HomePage.html
<!DOCTYPE html>
<html xmlns:wicket="http://wicket.apache.org">
<head>
<meta charset="UTF-8">
<title>Wicket Example</title>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
</head>
<body>
<div class="container">
<h1>Drop Down Choice Example</h1>
<form wicket:id="form">
<div class="clearfix">
<label>Category: </label>
<div class="input">
<select wicket:id="categoryChoice">
[category options goes in here]
</select>
</div>
</div>
<div class="clearfix">
<label>Number: </label>
<div class="input">
<select wicket:id="numberChoice">
[number options goes in here]
</select>
</div>
</div>
<div class="controls">
<button class="btn primary" wicket:id="submit">Submit</button>
<button class="btn primary" wicket:id="reset">Reset</button>
</div>
</form>
<div wicket:id="outputContainer">
<h3>Output</h3>
<p>Chosen Category: <span wicket:id="category">[chosen category goes here]</span></p>
<p>Chosen Number <span wicket:id="number">[chosen number goes here]</span></p>
</div>
</div>
</body>
</html>
Then The Java source: HomePage.java
HomePage.java
/*
* HomePage.java
*
* Created on 29 January 2012, 14:00
*/
package com.myapp.wicket;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
import org.apache.wicket.ajax.markup.html.form.AjaxFallbackButton;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.StatelessForm;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
public class HomePage extends WebPage {
private final String[] fooList = new String[]{"Even", "Odd"};
private final Integer[] even = {2, 4, 6, 8, 10};
private final Integer[] odd = {1, 3, 5, 7, 9};
String category;
String number;
WebMarkupContainer outputContainer;
public HomePage() {
add(new MyForm("form"));
outputContainer = new WebMarkupContainer("outputContainer");
outputContainer.setOutputMarkupPlaceholderTag(true);
outputContainer.setOutputMarkupId(true);
outputContainer.setVisible(false);
add(outputContainer);
outputContainer.add(new Label("category", new PropertyModel<String>(this, "category")));
outputContainer.add(new Label("number", new PropertyModel<String>(this, "number")));
}
public class MyForm extends StatelessForm {
List<String> categoryList = Arrays.asList(fooList);
List<Integer> numberList = new ArrayList<Integer>();
public MyForm(String id) {
super(id);
setOutputMarkupId(true);
DropDownChoice categoryChoice = new DropDownChoice("categoryChoice", new PropertyModel(HomePage.this, "category"), Model.ofList(categoryList));
final DropDownChoice numberChoice = new DropDownChoice("numberChoice", new PropertyModel(HomePage.this, "number"), new PropertyModel(this, "numberList"));
numberChoice.setOutputMarkupId(true);
categoryChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
if (category.equals(categoryList.get(0))) {
numberList = Arrays.asList(even);
} else if (category.equals(categoryList.get(1))) {
numberList = Arrays.asList(odd);
}
if (target != null) {
target.addComponent(numberChoice);
}
}
});
category = categoryList.get(0);
numberList = Arrays.asList(even);
add(categoryChoice);
add(numberChoice);
//add and implement controls
add(new AjaxFallbackButton("submit", this) {
@Override
protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
outputContainer.setVisible(true);
if (target != null) {
target.addComponent(outputContainer);
}
}
});
add(new AjaxFallbackLink("reset") {
@Override
public void onClick(AjaxRequestTarget target) {
MyForm.this.clearInput();
outputContainer.setVisible(false);
if (target != null) {
target.addComponent(MyForm.this);
target.addComponent(outputContainer);
}
}
});
}
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public String getNumber() {
return number;
}
public void setNumber(String number) {
this.number = number;
}
}
Code Briefly Explained:
The most important part of this example is the AjaxFormComponentUpdatingBehaviour which is used to listen for event changes(selection change) and then populating the other drop down box.
Snippet here:
categoryChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
if (category.equals(categoryList.get(0))) {
numberList = Arrays.asList(even);
} else if (category.equals(categoryList.get(1))) {
numberList = Arrays.asList(odd);
}
if (target != null) {
target.addComponent(numberChoice);
}
}
});
Running Output/View:
In the immediate future, i would make available the above code and the whole project on github. Admittedly, this is a fairly simple example especially to the experienced wicket users. But then it is still my first open contribution to the building documentations available in the wicket community.
Lastly, I should mention that the above code uses wicket 1.4.10. wicket 1.5 is the latest stable version(s) of wicket and we are all advised to migrate.
N.B:
I used twitter bootstrap in laying out the form. Twitter bootstrap is a nice open source css framework from twitter that allows fast bootstrapping of web apps
#FuelSubsidyRemoval, #OccupyNigeria; The End Game
Today marks the third day of the embarked nationwide strike against fuel subsidy removal and a large number of the nigerian population have been coming out in mass to protest this policy. A lot of articles, debates, sessions etc have already been written and held on the wrongfulness of this policy. All these points to the fact that majority of Nigerians do not want this fuel subsidy removed. For the purpose of this post, I’ll tag this movement the #ReturnOfFuelSubidy movement. This movement would be tamed once government decide to return back to the status-quo of N65.00 per litre and meet other subtle demands.
The other movement is the #OccupyNigeria. Unlike the former, #OccupyNigeria movement has been brewing for a very long while now and consists of individuals, groups, NGOs, who at the very core have same goal of sensitizing the people on the need to participate and demand for accountability, transparency and effectiveness in government. This movement recognises the ridiculous display of corruption in high places in governance and are ready to fight it. #OccupyNigeria has a different set of demands not limited but including the demand that fuel subsidy be returned and lot more has stated here. They do insist that they won’t back down from the protests until these demands are met.
Observing the unfolding of events and incidents whilst participating in both movements these past few days, weeks, months and even years. I would say a large player in the #FuelSubsidyRemoval group is the Nigeria Labour Congress (NLC), Trade Unions, and other labour unions. With their help the nationwide strike was commenced and then nigerians were able to make stronger protests. I do fear that once government does decide to return the fuel subsidy, this group of people would peddle down and the government may yet find another way to cause hardship to the people while still satisfying their own greedy desires and embezzling the nation’s funds in the process. When this happens, I can’t help but wonder how #OccupyNigeria would carry about fighting and meeting its demands as I do believe their voice would be back to whispers. But I digress.
So far so good (or bad), the administration of President Goodluck Ebele Jonathan which i’ll henceforth refer to as GEJ as remained adamant that fuel subsidy has come to stay and not even the directive by the house of representatives, senate and the protest of nigeria people would convince them to return back to the former price of N65.00. This is indeed scary and has got me thinking about the end game of all this. My thoughts do not excite me.
GEJ by stubbornly refusing the demands of the people has already created unrest in the country opening the nation to either of an uprising, civil unrest and/or even probably a military coup d’etat. As a move to cool off the military, I hear that their wages were recently increased during this period. If this is indeed true, then we do have at our hands a scheming government. How do the people fight back if government indeed keeps to their stubborn stance? We are probably left with #OccupyNigeria.
“There is no revolution without ARMS”.
How does #OccupyNigeria intend to make government meet their demands? What happens if government doesn’t bend to their demands and NLC calls off the strike either because government meets the N65.00 per litre demand or because the strike becomes weakened by the mere fact that people are tired and need to hustle for their daily bread? How do you enforce that a stubborn government does listen to you?
One end game move is that Senate somehow impeaches the president successfully. This would mean we have with us Sambo the current vice president. I doubt if Nigeria does want Sambo or even Mark. Is the problem with democracy?
Another possible outcome of all this is that civil unrest breaks down in the country and military take over in a quest of quenching the unrest. We would then have in alms of affairs a military head of state. History has already taught us that unlike democracy, it is even more difficult to check a corrupt and bad military government.
A revolution – as another end game? A lot of people have requested that the government be refreshed. I interpret this to mean a revolution. There cannot be a revolution without arms or bloodshed. Anybody who have taken a keen look at Nigerian political scene and governance would know that we keep cycling same corrupt people to rule us. People with this school of thought, hence suggests that the only way Nigeria can move forward and get better as a nation is if we flush these people out. But I do say, that “There is no revolution without arms”.
Like all of you, I am confused as to where this is getting at but unlike most I am thinking of the end game. I would like to enjoin everybody reading this blog post to take take a stance. Are you for just #FuelSubsidyRemoval or #OccupyNigeria movement. Are you prepared to enforce your demands? How far are you ready to go? If NLC does call off the strike and other demands haven’t been met, are you prepared to turn deaf ears at NLC and continue to fight and occupy?
Thinking about this end game now rather than later would help us all.
No Love…
This would probably be the shortest blog post I’ll be writing. This year again I have failed in writing and documenting some of the works I have done. I am not even sure working with a private company whose codes are supposed to be proprietary is a good enough excuse. X_x
I sincerely do hope I can drag myself off this, write more blogs in future that would come across as technical, political, and any other issue that catches my interest.
This blog needs more love.