Translate

Wednesday 17 April 2013

Integrating Eclipse Dynamic Web Project with Struts 2 and Maven and DWR



Note: To see code snippet in this post, use either Google Chrome or Mozilla Firefox.
I have walked through all google results (figuratively) to find a way to integrate Struts2 with DWR and make integration for maven with Dynamic Web Project. Because most of the tutorial will shows you how to create Struts2 or DWR project with either maven or dynamic web project. Why not using both? So, my goal here is to create a dynamic web project with maven to manage its library dependency and making an orchestra between struts2 framework and DWR to work together.

Here my friend take the guide to set up a dynamic web project in eclipse and use maven for dependency management. You will learn how to create a struts 2 project and also integrate direct web remoting  (dwr) library in it. I assume you already have following setup in your environment:
  1. Eclipse IDE 3.7 (Indigo) because I avoid using Juno since it has some significant bugs
  2. M2E plugin installed in your Eclipse 3.7
  3. DWR 3.0 RC library (I avoid using one provided from maven repository due to some error)
  4. JDK 1.7 (I am using JDK 7)
  5. Tomcat 7
Create New Dynamic Web Project
  1. Click and Select on File > New > Dynamic Web Project
  2. Put Project Name TestWeb and Click Next. Then Change the default build output folder into WEB-INF
  3. Click Next then check the option Generate Web.xml and click finish


Creating required folder for Maven
Before converting to Maven Project, we need to prepare what is missing for standard maven directory structure. Because Maven will have standard directory as:
  • src/main/java : all your java code here
  • src/main/webapp : all your web files here including WEB-INF folder
  • src/main/resources : this is optional, but lets create this folder to store struts properties and xml configuration
Take a look at our folder structure created from Eclipse Dynamic Web project. We will remove the WebContent folder and create the folder above in the existing src folder. 

The picture is original web folder and some instruction which folder to remove and what folders to create on which folder. To create new folder, simply click on the TestWeb root folder, and select New > Folder. Create the main folder first, and then under that main folder, you create java, resources, and webapp folder. 

So the final result of your folder structure will be like this:

Converting to Maven Project
After the maven's required folder is created, convert the project by right-clicking on the TestWeb root project folder, select Configure > Convert to Maven Project. On the window dialog Create New POM don't forget to select WAR as packaging method.


The package Name can be whatever you would like to prefer, so it is not mandatory to follow the naming with com.aryabisma prefix. Click Finish and the final result must be like this with errors:


Modifying Project Properties setting 
Next we need to modify some project properties setting to remove errors and make the project works. 
Right-Click on TestWeb root project folder then select Properties
  1. Change Project Facets Java to 1.7, then apply
  2. Change the Deployment Assembly with the following setup

  3. Change Java Compiler with JDK Compliance level 1.7, don't forget to uncheck the compliance first.
  4. Create folder WEB-INF/lib in src/main/webapp so that it become src/main/webapp/WEB-INF/lib and put DWR library there.
  5. After that, open project properties again and select Java Build Path, then open tab Library. select Add Jars then navigate to the dwr.jar we put on src/main/webapp/WEB-INF/lib. Hit Ok
  6. Remove the resources folder in the source tab under Java Build Path properties in Project Properties. So the result will be like this.
  7. I almost forgot to tell you that we need to change the JRE System Library int jdk 7, the one that we use for eclipse. So in the Project Property dialog, open tab Libraries, remove the JRE system library (1.5), then click on Add Library, select Jre System Library, and  select Workspace defaule JRE (1.7) 
Add Struts 2 and DWR Dependency
We already have the initial setup for Dynamic Web Project with Maven dependency management, now we add struts library and its dependencies. Put these code in your pom.xml 
pom.xml

Create Configuration File for Web deployment, and DWR
Now create a dwr.xml on the src/main/webapp/WEB-INF folder. Put these line in that file.

dwr.xml

Next, create web.xml on the same location with dwr.xml. Copy these line into that file.

web.xml



Now your webapp structure should be something like this.


Create Java class and jsp for DWR 
Create package com.aryabisma.asyncjava and make AsyncProcessor.java file with these line

AsyncProcessor.java

If you modify the package name and the java class name, you should modify the dwr.xml creator configuration to match with your new naming. Now Create the index.jsp file on src/main/webapp folder to make a call to method in AsyncProcessor.java as defined to be AsyncProcessor javascript in dwr.xml. Put these line in that index.jsp.

index.jsp

Create Java class and jsp for Struts2
Create package com.aryabisma.struts2 and make LoginAction.java file with these line.

ActionLogin.java

Create Login.jsp file with these line to make a form with action that mapped to ActionLogin.java controller

Login.jsp

Create Welcome.jsp for result page after the login action.

Welcome.jsp

Create ApplicationResources.propertiesunder src/main/resources folder. This file hold all the labeling and message text used in Login.jsp and ActionLogin.java, so that you have centralized place to manage all the labeling and message text.

ApplicationResources.properties

Create struts.xml to save mapping of action along with its success and error result.

struts.xml

Final Project Structures and Deploying to Tomcat Server
Now, your final project structures should be similar like this at least.



It's time to build the project and deploy it into Tomcat Server. To build the project, right click on the TestWeb root folder, then select Run As > Maven Install. you can deploy it manually to tomcat server or select Run As > Run on Server in eclipse. The final result must be similar to this demo page.

FYI: I still have problem with the integration due to struts filtering. So that, whenever you enable DWR debug as true, and try to see the exposed methods at /dwr/ web path, you will hit 404 no action mapped. But, if you remove the struts2 filter it will works and you can see the exposed dwr method.

Tuesday 9 April 2013

In to the Cloud: Jelastic, Java and Php in the Cloud

Cloud, Cloud everywhere. Believe it or not, in less than 5 years Cloud has becoming a very vibrant technology. Apart from its purposes that provide accessibility everywhere anywhere for individuals, this technology helps raising small to large scale enterprise businesses to reach effectiveness and save costs. Prior to Cloud, SMEs have to spent more costs in IT infrastructure just to run their own business critical application. Hiring Network professionals, dealing with vendor for servers and networking hardware, managing down time to setup and maintain their infrastructure to keep their system online. Just imagine how painful it was, how much time they spent to troubleshoot, mitigate, and maintain infrastructure to support their business application. Unless your business is providing Iaas and PaaS like most of Cloud vendor does, this is non-sense to your business nature.

Jelastic is Cloud that provide Java and Php platform as a service. But it is far better because it also provide Virtual Dedicated Server in which you will have root access to the server, like a virtual private server, but with very very transparent an manageable costs that you can control from the OS level to application level. You can set up load balancing, high availability, application server environment, etc through its easy to use web interface. Develop and deploy to Jelastic with a few simple click to setup the environment, or clone the existing environment. That's all, what are you waiting anymore? stop that bloody painful back end management and let them do that for you, unless you really want to have in-house back end system. With 7 Euro/month (according to my lowest topology setting ) it is worth it to be your own research and develop or hobby environment. For bigger usage or SMEs, these setting can be adjusted for more performance, you don't need to invests much money and deal with headache to plan system migration whenever you have hardware upgrades or failures.  Here is a video about Jelastic and screenshots from my Jelastic account.




Monday 8 April 2013

HOW TO: Set Tomcat 7 runtime in Eclipse

It is pretty handy to manage your run time server from within IDE, so you can handle development easily and focus on it. Here I show you how to set it on Eclipse.


  1. Go to Server tab at the bottom of your eclipse, or you can open it by opening Window > Show View > Others then search for servers. yes click that, and click new server wizard.

  2. On the next window, you select the target runtime for tomcat 7, and click next. 
  3. on the next page, you browse for the installation folder of your Tomcat and select the JRE, to set up custom JRE go to step 4 by clicking the installed JRE, otherwise just select workbench default jre just skip to step 5.
  4. To add new JRE, click add button. and then select the Standard VM, then find for the directory where you put your preferred JDK, and click finish.
    after you click finish here, then you click Next then Finish at the window shown in point 3, or just click Finish there.
  5. There is your server already set up.
    Tadaaaaa... congratulation. It is done.

    But Wait, It does not work fine... Trust me
    Eclipse will copy the configuration file of tomcat server into your workspace and then whenever you start the server, it will show server started, but when you hit http://localhost:8080 it will show 404 page not found. so Whats wrong? actually we should tell eclipse to use the existing server configuration as in your existing server installation. 

    Double click the server there, and in the server overview, look at the server location, then select the second option to use the tomcat installation. 
    That is it, now start your server and check it on the browser.

    Note: I use eclipse Indigo, but this how-to should apply to any version of eclipse. should you have any question, just post on the comment.


Thursday 4 April 2013

How entrepreneurs can ruin technology company?

Image courtesy of inc.com
The title is obvious, isn't it? how come you run a company without entrepreneurs? doesn't it good that you need entrepreneurship to keep your company in business? well, the answer it not always. Especially in company that rely on technology as its domain business and should keep innovation as the heartbeat of its selling point to the market. Technology by any means is talking about innovation that may lead into discovery and invention of something new, something different, and something that will provide advantage and better way of life for businesses or individuals. It does risks the company with business loss if the innovation failed in the market, but everything has risks and you can mitigate risks by doing market research while the idea is in incubation stage before it is out into the wild. When your company sold to bigger company who might not know what is technology and only concern the revenue gained from your existing products, then you are doomed. Your creative and innovative driven culture can be swapped into more formal, meeting-driven and profit driven culture.


Why startups company can bring many ideas and innovation into beautiful products and services? because they have small team, less leadership board, which means people do not need to hesitate to speak up their ideas, and there are not many leaders and management to be convinced to take these ideas up. They just sit together with the team as equals, talk about how to do it, what are improvements or advantages of making this idea into product, and woalah, innovation come out. Do you remember the law suit case between Apple and Samsung, and how some people talked that the top leader of Samsung wanted the Galaxy to be as beautiful as iPhone and no one could argue him to come with different idea that might be better than iPhone. That is just a small example, another example is when your startup company is growing and big venture buy your company, it does not really good idea somehow, because when the innovation culture turn into business culture that put revenue as main currency instead of beautiful innovation, then  you will regret your decision to sell your startup company.

Entrepreneurs are risking their business if they keep doing the old-fashioned management style for tech-company. Old-fashioned business, in my own words, is doing too much meetings, too much thinking, and too much leadership that will cause innovation and ideas bottleneck. Instead of following where the money flows, why don't we make the money flows to us. But how? at the old time, CEOs take action based on the markets. But now everything changed, especially for startup company. You take action based on innovation, and let the market shaped by itself and flows the money to your company revenue.



Wednesday 3 April 2013

How To: MySQL - Set Global variable for Maximum Allowed Package

You should feel bad if you are going to import data which file size is quite big and MySQL would not accept the query because the package data being sent is too big from the maximum allowed setting. To fix this, you can set variable max_allowed_packet to accommodate the query size of your data. Here the command to run in query:

SET GLOBAL max_allowed_packet=32*1024*1024
run that command in your open connection, and that connection session will allow for a maximum 32 GB package size. but you should remember that this setting will be reset if close the connection or restart the server. To make it persistent after restarting MySQL, you should change/add this variable value to the configuration file of MySQL. In windows you can find file my.ini at your MySQL installation folder, and in Linux you can find it at /etc/my.cnf . Append this line at the end of the file:

max_allowed_packet=4096M
Try to restart and check if now you are able to sent big query size. If it still not working, try to set bigger value.

Tuesday 2 April 2013

Project Delivery Crisis: Software developer issue with irrational expectation

Project delivery is important  issue that define the quality of service of a software vendor. Keeping good coordination and developers morale is prominent since they are the heartbeat of project delivery. No matter how many resources do you have, how good your managers are, if you cannot make your developers in good morale and distribute workload to its appropriate working line, then your project is considered failed before it even done. High turn over in IT industry is normally accepted, but if at the same year there are more than 10 developers moving out, it might be an indication of something miss in project management.

Common breakdown in the development department are Project Manager, System Analysts, and Developer. At the same time, these developers may be entitled as Software Engineer which role is analyzing solution to be implemented into codes by breaking down the big concept into smaller fractures so that it can be easy to do and understood before it is written as code. System Analysts are supposed to provide system requirements, sets of logic and rules, and define the standards for software development being tailored for customers. Project Managers are dealing with clients, coordinating project progress and resolving problems that occur in development area that may affect clients satisfactory and company revenue.

Do you wonder where is the missing point? it was the dualism of software engineer and somehow project manager do not manage rational expectation for project delivery. Either the PM want to keep his record good and clean, or want money comes faster without considering how complex the project will be. System Analyst cannot do anything due to pressure from top level, and just create requirements, specifications, and task timeline without buffer time. At the end, It's developer who are frustrated by pressure from all around, developer is expected to breakdown the requirements and specification into coding planning as well as implement it into code. This requires extra times and efforts, but management seems do not want to tolerance this extra time. So whenever bugs/error occur the most first person to point is developer. Bug/Error is not always come from developer side, it sometimes come from not rational project delivery expectation that impact the whole software development life cycle.

Keeping good morale of developer is simple, it is like trading with social tolerance. Company want developer to work full time for them, and keep up with the tight deadline schedule whenever project plan is not executed well as expected, then special rewards must be given without being hold. It is very disappointing if you have worked hard but your reward is being hold until next year. Software vendor does not earn money from customer, but they earn money from the sweat of developers. What if those developer who hold critical module stopped working like a jammed machine? throw that jammed machine and acquire a new one? One should remember that software engineer is human, not robot. New guys may come, but will takes another learning curve.

To cope with this crisis, we must think the opposite from bottom to top. CEO must aware that their power is their human resource, which is their Software Development Department hold the biggest stake. Software Development consists of three main working line, they are requirements gathering, coding, and testing. Later in it may be extended into implementation and integration, but that is another thing. Make the application done is something, and deliver the project done is good thing. Here are best solution in my opinion to cope with this software developer crisis:


  1. Clear and complete requirements: In tight schedule there may be hard to provide fully completed functional specification and requirements, but to make software developer life easier and faster, system analysts must give a simplified technical documents that provides brief description and workflow of the project as well as the module and processes, technical breakdown that include a standard UML diagram from use cases, actors, module and classes, as well as sets of standards and rules for this specific project. Make it done first, sent it to software developer, then continue doing client oriented documents. 
  2. Use generalization as much as possible: It is very useful and fastest strategy to cope with tight schedule, but to find out which one and modules can use generalization, this must be either comes from System Analysts or Software Developer. As mentioned at the first number, It should be part of system analysts because software developer must implement the code as fast as possible with less mistakes and less time.
  3. Special rewards and no blaming: No one is perfect, but also to boost morale, rewards is required. Since irrational project delivery is priority, rewards must be given respectively after the project done, regardless of it is delivered or not. why? because if project cannot be delivered well, either the problem is on development side or management side. but with the time given so irrational, then it is management failure, period. Do not blame development guys (analysts, engineers, and tester) when it fails, ask yourself why plan failed. It's better to encourage rather than blaming and blind-forcing to finish this task. You don't want to lose your development assets after the project's done, do you?
  4. Maintain client requirements: somehow, following what clients wants can ruin the whole project development. It is best to keep what already agreed and signed at the first requirement study, and if there are any change requests or additional features, deliver it on next phase/patch. So at least, project can be delivered first without mess, and be ready for patches and next phase. you cannot accept all requests to be delivered within the same timeline without having extended development time due to side-effect . 
When project delivery has come into critical stage, company must sacrifice more costs for keeping development team morale and wills boosted and do remember to respect whatever have been done as a team. Because if projects done beautifully, the words and awareness will spreads out affecting many potential customers. It is a bargain, to persuade people to work not in normal time and pressure, then compensation is required. If having three line of development is not enough, then consider having Business Analysts line to study user business model, business requirements, and let the System Analysts to do more technical analysis as it is supposed to be.