Friday, August 28, 2015

How to create a modularized ear project in maven

This post is one way of creating a typical javaee6 maven project that contains ear, web, ejb and api. The output of course is an ear file that contains (web, ejb and api).

How it looks like (assuming our top project is named ipiel):

*Note that ipiel, can also be a child of a another project, which could be a main project where ipiel is just a component.

How to create the 5 listed maven projects above (I'm assuming you have eclipse with maven plugin installed):
1.) ipiel (the main pom project)
  a.) In eclipse create a new maven project, skip archetype selection so it will only create a maven project that has a src folder no main/test.
  b.) groupId=com.ipiel
       version=leave the default

2.) ipiel-api (where interface is declared that is shared between ejb and web)
  a.) Right click the ipiel project and select new->maven module
  b.) Since this will contain java files, select maven-archetype-quickstart, you can filter "quickstart"
  c.) groupId=com.ipiel
       version=leave the default
  d.) Create a class Bird and add a method fly.

3.) ipiel-ejb (the backing/manage bean)
  a.) Right click the ipiel project and select new->maven module
  b.) Since this will contain java files, select maven-archetype-quickstart, you can filter "quickstart"

  c.) groupId=com.ipiel
       version=leave the default
  d.) Add dependency to ipiel-api, and implement the Bird interface, in a class let's say Eagle.

4.) ipiel-web (the ui project, where you define your xhtml files)
  a.) Right click the ipiel project and select new->maven module
  b.) In the maven filter enter "web" and select org.codehaus.mojo.archetypes webapp-javaee6.
       It's a simple web archetype and we need to add some files to it.
    1.) Add a new source folder /src/main/resources.
    2.) Inside /src/main/resources create 2 folders /META-INF and /WEB-INF
    3.) Normally we have beans.xml and web.xml inside /WEB-INF folder and /META-INF contains MANIFEST.MF
  c.) groupId=com.ipiel
       version=leave the default
  d.) Make sure that you add maven-war-plugin in pom.xml.
  <!-- In version 2.1-alpha-1, this was incorrectly named warSourceExcludes -->
  e.) The web project is also dependent on ipiel-api, since it needs to call it's backing bean from the ipiel-ejb project.

5.) ipiel-config (where I normally place persistence and resource files)
  a.) groupId=com.ipiel
       version=leave the default
  b.) Create a new maven module, and select maven-archetype-quickstart, you can filter "quickstart"
I defined where my resources are in this project:

6.) ipiel-ear (the output project)
  a.) Create a new maven module project, skip archetype selection, so we have a basic maven project
  b.) groupId=com.ipiel
       version=leave the default

Friday, July 24, 2015

Android Studio - Displaying List View Inside AlertDialog

Android Studio - Displaying List View Inside AlertDialog

1.) Follow this code:
>Note: custom_dialog_layout.xml is the layout that will pop-up
>Note: row.xml is the item used for populating row
AlertDialog.Builder  builder = new AlertDialog.Builder(new ContextThemeWrapper(MainActivity.this,;

builder.setTitle("Custom Dialog");

View customView = LayoutInflater.from(MainActivity.this).inflate(R.layout.custom_dialog_layout, null, false);

ListView listList1 = (ListView)customView.findViewById(;
String[] stringArray1 = new String[] { "Bright Mode", "Normal Mode" };
ArrayAdapter adapter1 = new MyListAdapter(MainActivity.this, R.layout.row, stringArray1);


builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {


builder.setNegativeButton(, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int which) {

Android Studio - Creating Material Design App Bar

Android Studio - Creating Material Design App Bar

1.) Set-up the color that we'll use for the app bar:
>Create a new xml inside values and name it color.xml
    <color name="ColorPrimary">#FF5722</color>
    <color name="ColorPrimaryDark">#E64A19</color>

2.) Using the previously declared color, change the style.xml to apply the colors:

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="colorPrimary">@color/ColorPrimary</item>
        <item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
        <!-- Customize your theme here. -->

3.) Make a tool bar:
>Create a new xml layout file and name it tool_bar.xml
<span style="font-size: x-small;"><?xml version="1.0" encoding="utf-8"?>
< xmlns:android=""

4.) Use the tool bar:
>Insert this code to wherever xml layout you want to display the tool bar

5.) Adding additional buttons inside the app bar:
>Go to menu_main.xml and add/paste the code below

Tuesday, July 07, 2015

How to generate jax-rs documentation using maven

To generate the jax-rs documentation automatically using maven, we need to add some plugins in the build section of the project's pom file.

To avoid running this plugin every time you invoke mvn install, you can create a separate profile for it.

Here's the plugin definition:




And here's the content of enunciate.xml.
<?xml version="1.0"?>
<enunciate label="novaglobalapi" xmlns:xsi=""

  <include pattern="**" />

  <docs docsDir="restapi" title="Broodcamp REST API" />
  <c disabled="true" />
  <csharp disabled="true" />
  <obj-c disabled="true" />

Wednesday, July 01, 2015

Swift - Displaying Actionsheet for Ipad and Iphone

Swift - Displaying Actionsheet for Ipad and Iphone

A simple tutorial on making an alert view of type action sheet that works for iphone and ipad.

1.) First you'll need a button where you can attach your pop over when you're using iPad (in iPhone it not necessary). Then you'll have to create an outlet for the button (in my example i named it "btn_button") so we can determine the pop over location based on where the button is placed inside the viewcontroller.

2.) Inside the button's action, paste the following lines of code:

 let optionMenu = UIAlertController(title: "Choose Your Option", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
        let option1 = UIAlertAction(title: "Option 1", style: .Default, handler: {
            (alert: UIAlertAction!) -> Void in
            println("Option 1")
        let option2 = UIAlertAction(title: "Option ", style: .Default, handler: {
            (alert: UIAlertAction!) -> Void in
            println("Option 2")
        let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: {
            (alert: UIAlertAction!) -> Void in
        if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiom.Pad )
            if let currentPopoverpresentioncontroller = optionMenu.popoverPresentationController{
                currentPopoverpresentioncontroller.sourceView = btn_button
                currentPopoverpresentioncontroller.sourceRect = btn_button.bounds;
                currentPopoverpresentioncontroller.permittedArrowDirections = UIPopoverArrowDirection.Up;
                self.presentViewController(optionMenu, animated: true, completion: nil)
            self.presentViewController(optionMenu, animated: true, completion: nil)
The code is pretty straight forward:
-First we declare a UIAlertController where we can put our buttons.
-Second we created the buttons (Option1, Option2, and Cancel) and then we add the buttons inside the alert controller.
-Last we use the UI_USER_INTERFACE_IDIOM to determine if the device/emulator is an ipad or an iphone and do the necessary presentation for each particular device.

Wednesday, June 17, 2015

How to migrate your Godaddy web hosting to DigitalOcean

Lately I've been reading some good articles about DigitalOcean as a cheap VPS option in online hosting and so I decided to try and subscribe to one.

Since my wordpress website hosting is already expiring I decided to moved the hosting to DigitalOcean and renew the domain name in Godaddy.

Here's how I point my Godaddy domain to DigitalOcean VPS hosting and migrate my wordpress website:

*You must already have a DigitalOcean account with linked payment method (can be either a credit card or paypal).
*Copy all your wordpress files from Godaddy.
*Make a backup of your wordpress database.

  1. Create a droplet in digital ocean.
    1. Distribution = 15.04 x64
    2. Applications = Wordpress 14.04
    3. I chose $5 / month
  2. Follow this article to configure your server:
  3. Migrating your wordpress website:
    1. Using winscp, upload your files in your server's /var/www folder.
    2. Make sure that www-data user can write to the folders where it needed to, for example uploads. Note: use chmod. Note by default the uploaded files are owned by root, use chown and change the ownership to www-data.
      1. >chown www-data:www-data /var/www -R, change the owner and group of /var/www folder from root to www-data. This is done recursively.
      2. >chmod 774, means owner and group (read, write, execute) while others (read-only).
    3. Following the tutorial in #2, you should now have phpmyadmin installed. Restore your wordpress backup.
  4. We then need to point your domain name to the new ip address in digital ocean.
    1. To get your droplet's ip address, go to your digital ocean's droplet's page 
  5. Now that you have your ip address, go to DNS, and add a domain record like this: 
  6. We are done with digital ocean and we will now point godaddy's domain to digital ocean's server.
  7. In Godaddy expand Domains tab.
  8. Chose your domain then click Manage.
  9. In Settings tab, under Nameservers click Manage.
  10. Setup Type=Custom, then add the 3 nameservers below
  11. After adding hit SAVE.
  12. You should now see the 3 name servers in the next screen.
Wait for 5minutes, then try logging-in in your linux hosting, and in the terminal run:

The command above should give you your digital ocean's ip address and name servers.

And that's it! Your wordpress website must now be running in digital ocean. That's in less than 30mins :-)

Common problems I've encountered:

  1. 2 widget were broken, need to set the content again
  2. some folders are not writeable when I uploaded need to execute chmod.
Want to try DigitalOcean? Register with this link.

Thursday, June 04, 2015

How to generate wadl via maven plugin

So you've written your web service and would now want to create the wadl for it.

 Assuming you have your web project in eclipse with maven integrated this is what you have to do: 1.) Add the lines below to your pom, you may want to create it's own profile. For example api.

2.) Looking at the plugin configuration above, we now have 2 define 2 files:
<?xml version="1.0" encoding="UTF-8"?>
<applicationDocs targetNamespace="">
 <doc xml:lang="en" title="czetsuya-tech api">czetsuya-tech api</doc>

<?xml version="1.0" encoding="UTF-8" ?>
<grammars xmlns="" />

3.) Now all you need to do is run the command below in command prompt:
>mvn -Papi clean compile com.sun.jersey.contribs:maven-wadl-plugin:generate
// note that we use api profile as defined above.

Thursday, May 28, 2015

How to return soapFault in a jax ws web service in JavaEE

The code below is an example of how you can throw a soapFault exception when an error is encountered in your web service  call.

There are basically 2 things 2 take note, see comments in code.

//#1 - inject WebServiceContext
private WebServiceContext webServiceContext;

//#2 get the soapMessage, add a soapFault in body and throw the soapFault exception.
SOAPMessageContext jaxwsContext = (SOAPMessageContext) webServiceContext.getMessageContext();
SOAPMessage soapMsg = jaxwsContext.getMessage();
try {
 SOAPFault soapFault = soapMsg.getSOAPBody().addFault();
 Name qname = soapMsg.getSOAPPart().getEnvelope().createName("Client", null, SOAPConstants.URI_NS_SOAP_ENVELOPE);
 throw new SOAPFaultException(soapFault);
} catch (SOAPException e) {
 // TODO Auto-generated catch block

Friday, April 17, 2015

iOS Donut Progress Bar

The iOS Donut Progress Bar is an iOS library that you can integrate in your project to present data in a graphical way. Furthermore, it will allow you to get a live preview of the design right in the Interface Builder.

Inside the Interface Builder:

iOS Simulator:


  • Customizable width and color for line and border of the outer/inner circle.
  • Customizable text label.
  • Customizable color, opacity, radius, and offset for shadow of the inner and outer circle
  • Supports the iOS 8 adaptive layout
  • You can change all of this in the interface builder or in runtime.

Example Usage In Runtime

circleView.outerRadius = 20
circleView.oColor = UIColor(red: 244/255, green: 156/255, blue: 45/255, alpha: 1)
circleView.percentage  = 75
circleView.fontSize = 25
circleView.noOfDecimals = 0

To get the sample code, please visit this site.

Monday, March 23, 2015

What you should know before getting your own website

So you want to get your own website? Do you know what you should take into account before agreeing to have your website created by the experts? You will be tempted by the many offers that website developers have. It is all too easy to get overwhelmed by the stuff of things to do and to put into your website that you may forget to look at the prerequisites. So what should you look into before letting the website masters do their work? Here they are:


Fees. There is an expected amount of money that you will pay when you have your website created and designed. Usually, the package is meant for a year or so with specifications like web hosting and other services tied up with getting a domain name or website. However, there are also fees that you should know, like transfer fees. Transfer fees are fees that you pay when you opted to transfer your domain. Some website designers will charge you 2 to 3 percent more than your registration fees. So make sure that you ask about all the fees, including hidden ones. (Image at text: Fees)

Pay what you consume

Pay only for the year that you consume. When you are about to pay for registering your domain, make sure you check the expiration of the website or domain that you are buying. There are tools over the Internet that you can use to check it. You can readily Google the term “how to determine expiration of a domain or website” and you’ll get numerous helpful results. On the other hand, the webmaster should show what you paid for. If you paid for one year, then it should reflect that it is registered as such. If you paid 5 years, then it should show, too. (Image at text: Pay what you consume)

Keep record private and locked

Keep your records private. Be careful with your domain or website purchase. Make sure that you learn from the experts how to hide or modify your records so that database hackers do not get a hold of your personal data. If you don’t, soon you will receive a lot of spam emails. Make sure that when you do buy a domain, it is you who own the domain and not them representing you. (Image at text: Keep record private and locked)

Keep it locked. After purchasing your domain and have it designed accordingly by the web designers, make sure that you also have it locked. This ensures that your domain is not transferred and you don’t get any surprises of another person claiming your website.

Get your domain auth code

Get the domain or website authorization code. Some websites or domain requires an authorization code, especially when they get transferred. In essence, you should also have it so that you can readily transfer it, should you want to sell the website or domain in later years. (Image at text: Get your domain auth code)

One of the best ways to avoid any problems is to take time in reading the Terms and Conditions before you purchase a website. Ensure that you read everything, even the fine print so you won’t miss anything. Ask as many questions as you can. List down questions that you have and clarify it with the domain registrar before sealing the deal.