Sunday, 9 September 2012

Visualization concepts for portfolio risk and Performance

Visualising multi dimensional data is critical in understanding the performance of portfolios. Our research was focussed on the most innovative ways by which the risk and return of portfolios can be visualised to make informed decisions about the portfolio.

Here we have a parallel coordinates, This is the most interesting as it allows very dynamic filtering and also shows all the ratios from a single view for all accounts.

par

Mean – Variance scatter  plot visualisation. Should look like the efficient frontier if the accounts are efficient

Untitled-3

Top 5 and worse 5 accounts using a radar chart

Untitled-4

Portfolio history details over a period of time

Untitled-6

Another view of the Portfolio Analysis over a period of time

Untitled-11

All Portfolios in a single view

Untitled-5

TreeMap visualization of all portfolios. Size for Risk and Shade of blue for return.

Untitled-8

The visualization concepts have never been applied to portfolio theory!!!

Thursday, 2 August 2012

Presentation of Risk and Performance Monitoring system at Microsoft

Pictures of our group presentation of our risk and performance monitoring system at Microsoft. The Front end is developed in C# with WPF and the backend is developed in Java.

The WPF Client consumes a REST interface exposed by the Server.

Below is me making a presentation on the functionality of the systemIMG_9758

 

The ATRADE Team

IMG_9788a

 

Another team member explaining the Architecture of the system

IMG_9757

Microsoft Representative

IMG_9748

Our system is still under development but due to be completed soon.

Monday, 16 July 2012

Nose Dive into core Java: Understanding equals(Object o) and hashCode()

In this series, I plan to write on some of the fine details of the core Java API, some performance optimisations and some advanced Java concepts.

In this installation of the series(more to follow), we learn all there is to know about equals(Object o) and hashCode(), two fundamental methods that every serious developer must fully understand and keep in mind for the rest of their lives.

So what are these two methods?

These are methods defined in the Object class in java.lang package.
So every object you instantiate, inherits these methods because all objects extends from the java.lang.Object class.

The method definitions in the Object class are as shown below.

So why do we need to master them and what makes them special?
They are special and we need to master them because certain other aspects of the Java API rely on the correctness of these two methods for their efficiency and correctness when used, the biggest ones being the Collections API in the java.util package.

Even if you don't use the Collections API that much, you still need to know these two methods and their requirements thoroughly if you are implementing anything that has performance characteristics.

equals(Object o)

The purpose of the equals method is to provide a facility for us to be able ask, at any point, in the life of an object if an object we hold a reference to "equals" another object. It allows us to compare ANY two objects!

Literally, we want to ask

If we were to assign two numerical values to each of these two objects, should the two numbers be the same?

This question is very different from asking,

"Do the references for these two objects point to the same memory location?"

The second question is different because it asks if two objects are the same, i.e, occupy the same address space.

Just for emphasis, the equals method in the Object class and therefore the JDK asks the first one.

The default implementation of the equals method in the JDK is implemented as shown below.

Now whilst this implementation looks simplistic, almost like the guys at Sun(Ooops Oracle)are playing lazy, it has some serious consequences.

By using the equality operator on reference variables, the default implementation says if the two objects have identical bits, then they are equal! This is because, the equality operator on reference variables compares just the references being considered.

Understanding the equality operator

To fully understand what the code above does, lets remind ourselves quickly how the equality operator works with a quick example.

Consider the code below.

When we execute this code, this is the result we get;

Back to equals(Object o) method
So we can now understand that the default implementation, only asks if the two objects we are comparing have the same reference.

What does this mean?

Effectively, the JDK's default implementation answers our second question and uses that
answer as the answer to the first.

So the default implementation effectively says,

"If two objects have the same references, then they are also equal."

That in itself is not a lie since a reference can belong to only one object. No two different objects can have the same reference. So the default is true but a very narrow true.

The default implementation doesn't answer the first question comprehensively. It only takes the minimal truth that will always hold, but leaves the concept of equality of objects as a responsibility of the developer to decide. This is Object Oriented Programming(OOP) at its core.

You as the creator of the object must decide when two objects are equal. You can play along with the default implementation for trivial classes but in the end, it is your responsibility as the creator of the classes that represent the Objects in you domain space, to define the how equality is implemented among the objects you create.

The JDK developers have left a nice slot for you to answer what makes objects equal and that is why it is important to override the equals method in any non-trivial class that you implement.

What happens if I don't care about equality?

That's fine as long as you don't touch any of the Collections API classes, then you MAY be able to get away with your laziness. But if you touch any of them especially the ones that have Hash in their names, you run into serious trouble.

To fully appreciate it, lets think about why equality is important in the collections world.

We humans have used the concept of names to identify people since the stone age or possibly before then. But the flaw in the use of names is very easy to see. Just put 10 people in a room and give two of them the same name. The moment you call that name, we have a conflict. You must use another way to identify the one you want to call!

The creators of the Collections Framework sidestepped that conflict by partly relying on the equality of the objects in your collections. When Objects are put in a Hash* Collection, they go into baskets by the integer number returned by their hashCode() method. When you search for objects in that collection, the Collections API uses this value to identify the basket they went into.
Now in the selected basket, the collections API relies on the equals(Object obj) to find the object you are looking for. This means, if you have not overwritten the equals(Object o) method to define equality in a way you can recreate, and you use this Object as Key in a HashMap, then the only way you can fetch your items is to have a reference to the key.

Lets do an example to understand what we are talking about.

Suppose we want to use This class as a key for our data

And our data is actually represented by the following dummy class

Now lets see the how the argument made so far by implementing a lookup like this

When we execute to code above, we get the results shown below

In the second lookup, the result was not found because the equality operator used the references to try to find the Data.

To understand exactly why the second lookup failed, The following code shows the OpenJDK implementation of the get method of HashMap.

As you can see clearly on line;

The implementation is relying on the keys equals method key.equals(k). Since the default implementation uses equality reference operator(==), it means the second lookup will fail because it is in a different address location and hence the null result.

Also note that this implementation allows for null keys and will use getForNullKey() to find which ever object was stored under the null key.

The value returned can also be null as can be clearly seen in the last line.

I hope now you understand how the equals(Object o) method affects your use of the Collections Framework.

It doesn't stop with filling baskets

Well apart from using the equals and the hashCode() to store and retrieve Objects, The Collections Framework also relies on the equals in a number of places.

Typically all the contains methods in the List implementations rely on the equals(Object o) for retrieving the associated objects and these are clearly stated in the documentation for those methods. Also, the Set classes rely on equals(Object o) for making sure there are no duplicates.

All the following from the Map interface rely on a correct implementation of the equals(Object obj) method.

Also the following from the Collection


It doesn't stop with the Collections Framework...Contracts

The equals method also have contractual obligations it must adhere to. This is the Java API telling you to obey certain rules when overriding the equals(Object o) method.

The JDK's execution, performance etc are only guaranteed if your implementation obeys these rules. So if you override equals(Object o), your implementation must obey them.

The rules are - (ChRiST - No) - you can interpret it whichever way(for/agains/Swear) - just trying to help you and myself to remember

1. C-Consistent - For any two references x and y, irrespective of the number of times you invoke x.equals(y), it should consistently return true or consistently return false as long as none of the variables used in the definition of equals() have not changed.

2. R-Reflexive - For any reference x, x.equals(x) should return true. i.e., An object should equal itself! Logical, isn't it?

3. S - Symmetric - For any two references x and y, x.equals(y) should return true if and only if (iff) y.equals(x).
Put another way for programmers,

==> b must always equal true


4. T – Transitive – For any three references, x, y and z, if x.equals(y) return true, and y.equals(z) also returns true, the x.equals(z) must also return true.

5. N - Null Compare - for any non-null reference x, x.equals(null) MUST return false.
So its easy to that this implementation

followed by this call

will lead to compliance police call

Conclusion

.
1. Object equality is a responsibility of the developer to define. The default implementation only compares objects using the equality operator.

2. You MUST override equals(Object o) method of Object class if your class is going to be used as a key in any Collection, especially Hash-based collections(HashMap, HashSet, LinkedHashSet)

3. When you override equals(Object o), you MUSt obey the contractual obligations of the equals(Object o)method.

I will follow up with hashCode() in the next series.
Thanks for your time.

Thursday, 5 January 2012

Netbeans 7.1 is out but watch out before you grab that hot cake!

Good news Netbeans 7.1 is out with lots of support for the latest technologies ie JavaFx 2.0, Java EE 6 and JDK 7 but there are a few gotcha's if you decide to jump on-board now.


NB: I'm one of the noisiest Netbeans preachers wherever I find myself trying to win some eclipse souls. I just love the software but these gotchas are so raw I just want to warn you.

Netbeans 7.1 does not work with Subversion 1.7 period! So if you have just bought a new pc and you are setting up a new development environment or upgraded your subversion, or your company uses subversion 1.7, Netbeans 7.1 is not for you.

I now have to downgrade my subversion to use this but the advantages from Netbeans outweigh the downgrade so will have to. I have tried all the hack and command line client noise they usually throw at you and it just didn't work so don't bother trying

  • The JavaFx 2.0 project format in Netbeans have changed since the 7.1 RC2 so if you created your nice JavaFx 2.0 project with any of the previous Netbeans versions, such as 7.0.1, 7.1 beta or any version before the 7.1 RC2, your JavaFX 2.0 project will not run! The ant targets have changed and there is no migration support, so the only option is to recreate a blank project and copy your files manually.
  • Unfortunately, I don't have the patience for some other IDEs so my only options are to downgrade and to copy my files from my JavaFX 2.0 projects but I know its worth doing.
If you have any substantial development going on, then watch out before you grab that hot cake!

Tuesday, 3 January 2012

How to Set VM Arguments for Server in Netbeans - Solving PermGen space effectively

I'm an avid heavy Netbeans user but for some time now I have been fighting with a Horrible PermGen space error when debugging a Tapestry application.

After setting all the Options and environment variables in netbeans.conf, nbactions.xml, as a global environment variable, catalina.bat etc I still couldn't pass the VM options to the registered Tomcat server untill today I realised that, it's in the same place as you register the server!!!

And this took me ages to figure out (yea, daft me! ) so I'm sharing it here for my own reference and for anyone who runs into this.





Saturday, 28 May 2011

Yesss!!!!!!! Java FX Runtime is Distributable! The future is bright!

Wow after all the Licensing issues raised here by worried observers, Oracle has listened and now, you can happily write desktop applications with javafx 2.0 and distribute it under exactly the same License as Java itself.

You can read the mini statement here.

Let the java desktop revolution begin!Link

Monday, 28 February 2011

Adobe does Open Source in a very open way

While browsing the net, I came accross this list of Adobe supported open source projects that covers almost all your needs for your next multi media project.

http://sourceforge.net/adobe/wiki/Projects/

I must say I am really impressed and I hope some of these libraries will start finding their way into the Java ecosystem, especially GIL


Thank you Adobe for sharing.

Whiles there, you can also checkout this free webapp, ROME

Saturday, 18 September 2010

Hibernate in OSGi is a definite NO NO!

Recently I had the honor of trying to switch the persistence provider of our application so we can debug some performance issues and to my horrible suprise, there is no standard OSGi bundles for hibernate. Wow, with eclipselink, it was just a single jar! easy to find on eclipselink website, drop it in your auto start folder and bang! you are on your way.

After spending all day googling, I found some out of date bundles in SpringSource's repository. Wow, how difficult is it to produce an OSGi bundle if you have managed to write the code. I was thinking its just a packaging thing. Maybe am mistaken.

Anyway, after spending all that time, downloading all the gazillion dependencies manually and copying them to the felix auto start folder and also adding them to my pom file, the application finally started with all dependencies resolved.

As if that was not enough , I got an exception on startup
No Persistence provider for EntityManager named ...blah blah
What??
That was not enough? the persistence.xml file was there. The provider class specified in that file was there. I could clearly see it in Netbeans by just expanding the libraries tree and navigating the packages and the jar file that contained that class was also in the felix auto deploy folder.

I then started another googling session. It turns out hibernate has problems with classpath in OSGi. Ypu have to use some thread hacking to make it see your META-INF/persistence.xml and when you finish reset the classpath to what iwas before. At that point I just gave up. Its not worth the effort. As much as I love hibernate and hibernate-Search, its just not ready for OSGi. Will reinvent my search wheel with eclipselink

Friday, 13 August 2010

Is Oracle sinking the Java Boat? Please think of us too

A lot of people were wary with the Oracle Acquisition of Sun. For me, I was disappointed Sun was not acquired by a much more open source company. Oracle doesn't do open source with the heart and commitment Sun did. That is a fact!

The problem started becoming apparent when the big java people started leaving or walking away. That meant these guys were not comfortable in their new home.

Then it was followed by Oracle dropping some Sun products including the Sun Webspace server , project wonderland etc.

Then came Netbeans scaling down. In the new Netbeans 6.10 document, the only thing you read is performance and support for Oracle specific products. Nothing substantial to increase adoption or popularity.

Then finally Oracle is sending Google, a prominent Java shop, to the courts. Imagine all those frameworks and technologies Google has developed. What does oracle intend to acheive? More Money? Scare away big companies from Java? Or just Kill Java?

Who knows whats next?? Time for some Consipracy Theories.

My Message to Oracle
When making these decisions, think of the Millions of people who make a daily bread because they are able to write in Java and think of all those companies who employ them. If these companies fear to use Java, a lot of people will not be able to feed their families.

Please think of the Java Community! Please DO!

Tuesday, 3 August 2010

Top 10 Netbeans IDE Java Editor Shortcuts. Required for Daily Editor Usage.

These are my top 10 basic Netbeans Java Editor shortcuts that I use all the time everyday.
Hope it helps you increase your productivity.

1. Commenting. (This works in all Standard IDE editors, not just the Java editor). The commenting works regardless of the language, it will comment it appropriately. You can try it in the css editor or the XML editor


If no text is selected, the current line is commented appropriately.

2.Duplicate Current line.


3.Find implementation of an interface
With the cursor on the name of the interface,

When the list turns up, you can just click to open that class or use the keyboard to select and press enter

4. Fix Imports


5. Open class by name

Supports Camel case search and wildcards
To open any Resource ie css, html, text file use


6.Formatting

if no code is selected, the whole class file is formatted.
The formatting is controlled from that specified in Tools -> Options -> Editor -> Formatting

7.Rename a variable, class or method


8. Insert Some code.
This is one of the most used shortcut. Loads of options just appear when pressed.
The best way to utilise them is to generate getters and setters. declare all those properties,
and then press ALT+INSERT(Insert Key on the keyboard)
It works in a lot of editors, for example, in the html editor, you can easily generate Lorem Ipsum place holder.



9. Toggle Bookmark.
This helps when your file is very large and you keep scrolling up and down.

If the line is bookmarked already, the bookmark is removed and vice versa

10. Navigate bookmarks.
You can easily jump between bookmarks by pressing


Coming up next, Letting the IDE do the unnecessary typing. Stay tuned

Thursday, 10 June 2010

Wow, Netbeans Rocks! Now I understand why the hype

Recently there have been articles where new discovers of Netbeans have gone on to write articles about how cool the IDE does this and does that.

For someone who have been using netbeans on a daily basis EVERYDAY for the past four years, I found those articles to be generally boring as their new discoveries are things I have been using on a minute by minute basis for ages. To me they sounded sooo 2002..lol.

Anyway, at work, everyone uses Eclipse but I refuse to budge so still use Netbeans with the checkstyle plugin so I don't get done for code formatting and it all works smoothly once you setup you editor options. The ecosystem is just perfect. By the power of maven, I don't even touch the eclipse plugin in netbeans. Its all smooth.

However, one thing they always get me on is the eclipse shortcut "CTRL + SHIFT + T". Every eclipse guy knows it. At first I was a bit frustrated so I resorted to the netbeans Quick Search(CTRL + I) but its quite slow so they always moaned during code review as that circle thing kept turning and never brought the class.

Then I discovered the actual netbeans equivalent of "CTRL+SHIFT+T" was actually easy to use. It is "CTRL + O". Wow. Its even shorter that theirs. So these days during code review, I just go "CTRL + O" and there the class is. To even impress them, I just use the capital letters in the class name so for example for "CodeReviewModel", I just go "CRM" and there the class is. Wow!

Then they will go in which project is that class. There I am, stuck so I hover over the filename at the top of the editor and find the filepath and from there I deduce the Project.

Then today it struct me. What is that "Select in" thing at the bottom of the right click menu? It usually was Code folds so you can minimize the size of the file if it was 3000 lines.

I rightclicked again and there it was. I can select the file from the project, file and even in favourites!. Now, that is COOL!
To make it even COOLER, its got shortcuts! "CTRL + SHIFT + 1 " does make it soooooo simple.

I am no new user to netbeans. I even have Netbeans Platform Applications and plugins I have developed, but today am totally impressed I just thought I will let the whole world know, NETBEANS ROCKS!!

NB: I use Netbeans 6.8, the official release at the time of this writing.

Friday, 5 March 2010

In the age of DRYness, how dry are you?

In the age of DRYness, how dry are you. Here are 7 things to measure your DRY level.

  1. If you are using Code generators to generate CRUD functions for each of your entity controllers
    a.k.a DAOs or Entity facades each of which defines the same CRUD code with the Entity bean
    names changed, you are the Least DRY. Consider Generics and Delegation

  2. If you are using EJB 2.1 on Java 1.4, you can NEVER be DRY as there is just too much artifacts
    that are completely not reusable, ejb-jar.xml, CMP mappings, remote and local interfaces that
    don’t do anything etc. Another reason is because that platform promotes tight-coupling more
    than Channel4 promotes Big Brother!

  3. If you use Strings and scriptlets to generate your HTML ouput, your chances of being unDRY are
    above 80%

  4. If you are using the Command Controller pattern for your EJBs Session Bean or Front Contrliler
    Filter for your Views and using if clauses to select your handlers, you are 90% unDRY

  5. If all your JSP’s have the same top and bottom or if you use scriptlets to pull in the top and
    bottom such that for every JSP, there is an ‘include’ with a filename in String at the top, you are
    unDRY. Consider Templating

  6. If there is a lot of casting going on in your code, you are probably not DRY. Too much generic
    stuff that are not type safe!

  7. If you use Strings to construct your SQL statements, no matter what you do, you are unDRY even
    if you define them as global static final String!

Tuesday, 2 March 2010

Beginning Java EE 6. JSF 2.0 Tutorial. Part 3. Implementing Security. Access Control Logic via Annotations

OK. Its time for security. In the previous tutorials Part 1 and Part 2
we laid some foundational work. Now we are going to move into the real application development.

I did an extensive search on the internet looking for best practise with regards to implementing
security in a Java EE 6/JSF 2.0 Application. The reference samples from Sun..(Ooops Oracle..lol)
only provide example of how to use the Authentication functions of the Container. However, in
a real world, user access credentials and roles are mostly stored in the database and can therefore not
be hardcoded in the web.xml file.

Alternative solutions seem to use ACEGI Security for implementing Access Control Logic(ACL). However, I'm not keen on
learning Spring at this time just to implement Security. That solution also exponentially increase the number of
jars I have to worry about during deployment.

Another alternative is to use frameworks like JBoss Seam that provide in-built ACLs but at the time of this writing,
Seam is not compliant with the JSF2.0 Specification. Also , IMHO, this is not enough reason to adopt a full framework for this project,
So we will implemet it ourselves.

Lets get started.

I assume you have read Part 1 and Part 2. If you haven't please do as I will
make a lot of assumptions to tasks such as your simplea folder location, having run setenv.bat etc.
However, the main concept should be easy to follow without reading those previous sessions.

Also we are using the JSF 2.0 reference implementation (Mojarra). If you are using a different implementation such
as Apache myFaces, you will have to find the corresponding class names in your distribution and make the changes accordingly.
whiles we go along, I will mention it whenever we use anything Mojarra Specific

STEP 1

NB. Since we are not using an IDE yet, I want to say that if I say we create a
Java Class com.simplea.here.Foobar, I mean you should create the folder structure

com\simplea\here in the folder src\main\java and
in that folder create a file with name Foobar.java

Task 1.
Add the following to your pom.xml file


So your complete pom.xml looks like this


Task 1.
create Java Class com.simplea.jsf.extensions.CustomApplicationFactory

Enter the following in the file


NB: In this class, we are overiding a sun specific class. You must replace it with the corresponding
classname in your JSF 2.0 Implementation

Task 2.
create Java Class com.simplea.jsf.extensions.CustomActionListener
Enter the following in the file



Task 3.
create Java Class com.simplea.jsf.extensions.CustomApplication

Enter the following in the file


Task 4.
create Java Class com.simplea.security.SecurityManager

Enter the following in the file


The authenticate method is overloaded to accept different Security credentials depending on the client environment
At the moment it will only take UsernamePasswordCredentials so lets go ahead and create it

Task 5.
create Java Class com.simplea.security.UsernamePasswordCredentials

Enter the following in the file


Task 5.
create Java Class com.simplea.annotations.SecuredClass

Enter the following in the file


Task 6.
create Java Class com.simplea.annotations.SecuredMethod

Enter the following in the file


Task 7.
create Java Class com.simplea.handler.DashboardHandler

Enter the following in the file

This Handler has the SecuredClass Annotation on it. That means no method on it should
be called without being logged in. At the moment that is what we will use to test our SecuredClass Annotation

Task 8.
create Java Class com.simplea.handler.LoginHandler

Enter the following in the file

The Login Handler does not have any of our security annotations so you can click the login button.

Now lets test our classes to make sure they compile.

All these instructions are on the Command Prompt

Run setenv.bat. I assume you know how to do that.

Then cd to your simplea folder.

From now on, when I say type an mvn command, I will assume you have run setenv.bat in your current command prompt, and changed directory to the root of the simplea application folder.

type command

If that does not produce any errors, then you are good to proceed to the next Step. Make sure your code
compiles before proceeding to Step 2.

STEP 2


This is the site security story at the moment. To be built on.
Any user can access the index.xhtml and login.xhtml pages without having to log in.

To access the dashboard.xhtml page, the user must be logged in. At the moment, since only the LoginHandler
calls the securityManager.authenticate(), we will assume the user has logged in. In the next session when
we integrate a database, we will finish that up.


We accomplish the security requirements for the dashboard.xhtml by just annotating the DashboardHandler
with @SecuredClass



1.a) Create a file in the src\main\webapp\WEB-INF folder called faces-config.xml

1.b) Enter the following into that file



2.a) Create a file in the src\main\webapp folder called login.xhtml

2.b) Enter the following into that file



3.a) Create a file in the src\main\webapp folder called dashboard.xhtml

3.b) Enter the following into that file



We need to update the index.xhtml to include links to those pages

4. Delete the content of the index.xhtml and insert the following



NB
I am sure you have noticed the repetition in those pages and are wondering why dont we templatize them.Yes, we will do that
when we start actually designing the site. At this stage, its important we don't deviate.


Step 3


Undeploy Deploy.
Our undeploy deploy sequence is becoming repetitive so i have created a batch file to do that for us

In the folder C:\home\training\simplea, create a file called undeploy_deploy.bat

Enter the following into that file


Also, I have updated C:\home\setenv.bat so the default path is in the application folder
So open it and replace the content with this



Make sure Glassfish is running Instructions on doing that is available in the previous sessions

Open comand prompt, change directory to C:\home\training\simplea and type



and press enter

Now browse to



You will observe that clicking the dashboard take you to the login screen. Just enter anything
to login. Then you will be taken to the dashboard. Also see that once logged in, clicking the dashboard link
doesn't require you to login again.

In the next installation of this series,

We will integrate a Database,(Mysql 5) and JPA. Then we will complete this security by doing a proper check
from the database and acting according. Stay Tuned


Sunday, 28 February 2010

Beginning Java EE 6. Hand Holding Learning Trail Part 2. (JSF 2.0, Maven, Glassfish, Primefaces)

In the previous session we setup the skeleton of our simplea application.
In this installation, we will add a bit of Layout to the user interface before the next major atticle which
wil takle centralising Access control and security.

NB
This is only to beautify the look and feel. We will look at 'componentising' and taking advantage of
facelets in a future session. I actually dont feel easy just leaving it as this but in order not to be distracted
we will stay with this for now.

Lets get Rolling.


This is a continuation of a series. Please read the previous post to get a feel of what we are up to from here


TASK 1


Integrating 960 CSS framework.

As you may know, programmers are normally very bad at design and I am no exception. The 960 css framework is a grid framework that
allows you to position containers(divs) and other objects on your page very easily without having to worry about advanced CSS

It is a production ready open source CSS framework. Read More about it from here
So we will use that for our simplea application. I am hoping to create composite components for the 960 framework
later in this series.
OK, here we go.

1. In the src\main\webapp folder (this is a relative to the simplea folder), create

another folder called css.

2. Download the Zip version of 960 grid framework from here

3. Extract the ziped file into a folder.

4. In the code\css folder, copy the file 960.css and reset.css to the css folder created in step 1.

5. In the same folder ie code\css, create a file called styles.css

Enter the following in that file


6. Open the index.xhtml file created in the previous session and enter this



7. Create a package:

First cd into C:\home directory

Run setenv.bat

type setenv.bat and hit the enter key

Then cd into

then type


Now Start Glasfish by typing

then type


make sure previous version is uninstalled by typing

then type

then browse to

to see the application

You can now shutdown glassfish by typing

That brings us of the end of today's seesion.

Coming Up

Login and security in JSF 2.0. Stay tuned

Friday, 19 February 2010

Beginning Java EE 6. Hand Holding Learning Trail (JSF 2.0, Maven, Glassfish, Primefaces)

In this series and few more to follow, I will be posting on how to get started
with Java EE 6, JSF 2.0, Maven, Glasfish V3, Primefaces 2.0 and related frameworks.
This is just part of my effort to know it more. As I try to teach you,
I will be teaching myself even more. Lets get started.

I will try as much as possible not to use any IDE for now. Just plain text editor
so we can understand the basics.

This is to help us understand the structure of the whole web application.
Once we are done and we start using an IDE (Netbeans 4 Me), you will realise you have much control
you have over what you are doing because you understand how it all comes together.

Ok. Lets Run

ONE GOTCHA
Windows Notepad has the habit of adding .txt to my xml files which caused me a lot of trouble
untill I realised the files were being named wrongly. eg web.xml.txt.

Make sure your files are actually .xml and .xhtml files as windows will still tell
you they are even when they are not. (I used notepad++)

PART 1


Setting up our environment
I will not be jack of all trades. I will only use Windows. If you are using linux
or some other platform you must look for the equivalent commands.

Create the folder

This will be our Workspace will be
(Just make sure you understand what you are doing if you have to choose settings
to suit your environment)
I will generally work from c:\
Change the drive letters to suit your environment

Task 1. Install Java


Get Java from our old(rebranded) site. Make sure your version is >= 1.6 update 17
Get 1.6 update 18(the latest at the time of writing) from here
http://java.sun.com/javase/downloads/widget/jdk6.jsp
Install it to so your JAVA_HOME becomes

I will not install it because I already have it installed but it should be very easy.

Task 2. Install Glassfish V3 (Zip Version)


Download Glassfish V3(Zip Version). The zip version will help us to understand how things work
even more. Also we can easily clean up our environment easily if we dont need it.
Get the full zip (Not the Web profile) from
http://download.java.net/glassfish/v3/release/glassfish-v3.zip
NB: the web profile will do but as I'm new to this, I will stay out of trouble for now
Save it to

Right-click and extract it so that, after its done, your glassfish home will be

Open notepad or any editor and type the following

and save it as setenv.bat in the folder C:\home

Task 3. Install Maven


Download Maven from one of the mirrors here
http://www.apache.org/dyn/closer.cgi/maven/binaries/apache-maven-2.2.1-bin.zip
and save it.
Then extract it such that your maven home folder will be

Open your setenv.bat in the folder C:\home
and add the following

So your whole setenv.bat file will look like

Now open Command Prompt(I guess you know how to do that..lol)
and type each of the following, press enter after each command(Don't copy and paste)



You should get something like this after your last command

Our environment is almost set.
Lets test our glassfish.
With our command prompt still opened(If you closed it, make sure you run setenv.bat to set your environment and cd to the training folder before you proceed.)

type


then type

then browse to http://localhost:4848/
You should see glassfish loading.
For now, If we get a modal box asking us to register we will not register,so just do remind me later.
Hopefully, you will see a very nice man in a boat with a paddle.
That is the test. If you see that, you have completed part 1.

PART 2 Creating the Skeleton of the Application


On the command prompt

type

the type

then press Enter
This is a wrapped version so you can understand it. Use the one above to stay out of trouble


Maven will go off to do some stuff. You will get some messages on the console and the you will see
Build Successful. Yes. The Skeleton is now created.

Maven will generate standard maven project into our training folder.

The folder structure of the maven generated project is as shown below
Skeleton of a maven application

Open the pom.xml with your favourite editor . Delete the whole content and just paste this there.
(You can also just copy the parts you just need but to make sure we all make
the same mistakes, just change it all)

I have put a lot of comments in the pom.xml to explain each part so you can adapt it to suit your needs



Inside the main folder create another two subfolders


In the webapp folder, create another sub folder called WEB-INF

In the WEB-INF folder, create a new file called web.xml


For servlet 3.0, web.xml is not required. However, you need a way to specify your welcome file and also, the custom tags were not getting processed if i used .xhtml files instead of jsp
When we understand it more, we will know why it didn't work

So your entire directory structure will look like this:
The folder structure of the maven generated project is as shown below
Maven Web Application Directory Structure

Open the web.xml in your favourite editor and enter the following

In the webapp folder, create a new file called index.xhtml
Open it in your editor and enter the following

Now our basic application is almost complete.
Now cd into simplea folder by typing


make sure you run cd c:\home\setenv.bat if you closed you Command Prompt

then type

I all goes well, You will see the build successfull message on the screen.
That will create our war file:

Task 4. Installing the war file in glassfish


NOTE

If you shut it down, restart it using the instructions above . If you are doing that
make sure you run c:\home\setenv.bat before.

Now whiles Glassfish is running
Now go to

On the left sidebar, click on Applications
Click on the deploy button
On the next page, leave the selected radio button and click browse
Browse to C:\home\training\simplea\target and select simplea.war and click open.
When you return, leave all the defaults, scroll to the bottom and click ok.
That should take you back to the applications list page

Task 5. Enable and Run


On the applications list just tick checkbox for simplea and click enable.
When the notification comes that the application is snabled,
Just click launch to see the application

Task 5. Shut down Glassfish


type

then type

Coming up next. Designing the homepage and the Login.
Stay tuned