Tạo ứng dụng web nhanh và đơn giản với Grails (Phần 1)

Posted in Grails, Groovy, J2EE, Java, LightWeight J2EE with tags on Tháng Một 26, 2010 by hadv
Trước tiên bạn cần download grails framework phiên bản mới nhất từ trang chủ của grails (http://www.grails.org/Download). Phiên bản mới nhất tại thời điểm viết bài này là 1.1.2. Tuy nhiên, tôi sử dụng phiên bản grails 1.0.1 để làm demo trong bài viết này.

Sau khi download thành công file grails.zip về máy; các bạn giải nén vào một thư mục bất kỳ và tạo một biến môi trường GRAILS_HOME trỏ đến thư mục mà các bạn chọn để giải nén ở trên như ở Hình 1. Các bạn có thể thấy là các thư viện chuẩn cần để lập trình web động như Spring, Hibernate, SiteMesh, Jetty và một số thư viện hỗ trợ cho việc build, ant, và hỗ trợ chạy unittest, junit, cũng đã tích hợp sẵn vào trong grails rồi.

Hình 1: GRAILS_HOME

Ngoài ra, các bạn cũng cần chắc chắn là đã thiết lập chính xác đường dẫn của JAVA_HOME; ví dụ như trong Hình 2 và đã thêm đường dẫn đến thư mục [bin] của grails vào biến môi trường %PATH% của Windows như trong hình Hình 3.

Hình 2: JAVA_HOME
Hình 3: PATH

Sau khi đã thiết lập các biến môi trường xong, để kiểm tra xem grails đã được cài chính xác hay chưa, các bạn hãy mở cửa sổ command line và gõ lệnh grails như sau:

C:\Documents and Settings\hadv>grails

Hoặc

C:\Documents and Settings\hadv>grails help

Nếu các bạn thấy output ra màn hình command như bên dưới thì nghĩa là grails đã được cài đặt thành công và bạn đã có thể bắt đầu công việc thú vị là tạo một trang web động.

—————————————————————
Welcome to Grails 1.0.1 – http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: C:\dev\java\grails-1.0.1\grails
—————————————————————————-

Để tạo bộ khung source code cho một dự án web sử dụng grails rất đơn giản; bạn chỉ cần gõ lệnh như sau để tạo một dự án có tên là [LovePoem]

C:\dev\java\workspace>grails create-app LovePoem

Kết quả grails sẽ chạy các script có sẵn như trong Hình 4 để tạo ra bộ khung source có cấu trúc thư mục như trong Hình 5

Hình 4: Kết quả chạy script trên màn hình command line
Hình 5: Cấu trúc thư mục

Sau đó, các bạn chuyển đến thư mục dự án [LovePoem] vừa được tạo và gõ lệnh [grails run-app] để chạy thử trên Jetty như sau:

C:\dev\java\workspace\LovePoem>grails run-app

Cuối cùng thì bạn mở browser và truy cập vào địa chỉ [http://localhost:8080/LovePoem] bạn sẽ thấy màn hình như trong Hình 6 xuất hiện và cũng có nghĩa là bạn đã tạo thành công một dự án có sử dụng grails.

Hình 6: Màn hình mặc định của Grails

Đến đây thì bạn sẽ thắc mắc là đã tạo được cái gì đâu? Đúng như vậy, các bạn hãy kiên nhẫn đợi đến bài viết sau; tôi sẽ trình bày cách tạo các domain, các event và các services, các controller,… cũng như việc kết nối với database để có thể tạo ra một ứng dụng web hoàn chỉnh.

Securing Java applications with Acegi

Posted in Acegi, J2EE, Java, Security with tags , , , on Tháng Hai 22, 2008 by hadv

Securing Java applications with Acegi, Part 1: Architectural overview and security filters
This series introduces Acegi Security System, a formidable open source security framework for Java enterprise applications. In this first article, consultant Bilal Siddiqui introduces you to the architecture and components of Acegi and shows you how to use it to secure a simple Java enterprise application.

Securing Java applications with Acegi, Part 2: Working with an LDAP directory server
With the basics out of the way, you’re ready to discover the more advanced uses of Acegi Security System. In this article, Bilal Siddiqui shows you how to combine Acegi with an LDAP directory server for flexible, high performance Java application security. Learn how to write an access control policy and store it in ApacheDS, and then configure Acegi to interact with the directory server for authentication and authorization purposes.

Securing Java applications with Acegi, Part 3: Access control for Java objects
Bilal Siddiqui concludes his introduction to Acegi Security System by showing you how to secure access to instances of your Java classes. Learn why you need to secure access to your Java classes, how Spring creates and secures instances of your Java classes, and how to configure Acegi to incorporate class security in your Java applications.

Securing Java applications with Acegi, Part 4: Protecting JSF applications
Bilal Siddiqui continues his series by showing you how to use Acegi to secure JavaServer Faces (JSF) applications. Configure JSF and Acegi to work together in a servlet container, and explore how JSF and Acegi components cooperate with one another.

Software Development Top 30 Mistakes

Posted in Porject Management, Software Development, Software Development Manager with tags , , on Tháng Hai 20, 2008 by hadv

I have been developing software and web applications for nearly 11 years now.  Software development has come a long way since the days of Binary, Cobol, etc.  What still fascinates me about software development is the same mistakes made before, are still made today.  Below are the top 30 Mistakes that are made within the software development process.  It’s amazing to see that none of these have anything to do with the language itself.

  1. Not understanding the user’s needs. Lack of user input, or not even asking.
  2. Underestimating the size of the project.
  3. Rushing through the planning stage, or avoiding the planning all together.  Code first, plan later! BAD!
  4. Not testing early enough, often, or at all!  Make it a habit!
  5. Choosing the “Cool” methodology at the time, vs. one that has worked in the past. Which leads into my next point…
  6. Not using a methodology.
  7. Letting a software developer run the software development project.
  8. Bored, unmotivated team!  You have to motivate your developers!  If you can’t motivate, don’t bother trying to lead.  Your team will fall asleep, literally.
  9. Planning on catching up later.  You won’t… don’t even think it!
  10. Non Source Control!  Ouch.. not good people… and no, just installing a software package is not it…
  11. Deciding to switch your development tools when you’re already into the project.
  12. Allowing feature creep.  Just say NO!  Everyone will be happier in the end.
  13. Omitting necessary tasks to shorten the project plan.  Really, what’s the point of doing this?
  14. Insufficient management controls in the development project.
  15. Lack of high level business sponsorship.
  16. Adding people at the end of the project to “speed things up”.  You will only slow things down…
  17. No unit testing.  Heck if you can do it, use Visual Studio Team Foundation Server and set up some automated testing nightly.
  18. Stressed out software developers.  If you have managed to perform even one or two of these software development mistakes, you will have a stressed out bunch of programmers to deal with!
  19. Lack of error handling.
  20. “Off by one” errors.  These happen a lot during the software development process.. *sigh*.
  21. Typos…  Just use option strict and explicit please..  during one software development project, which I was on as a consultant, they were getting ridiculous amounts of errors everywhere… turned out the developer couldn’t spell and would declare variables with incorrect spelling.. no big deal, until you use the correct spelling when you’re assigning a value to it…  and  you had option explicit off.  Ouch to them…
  22. No understand the deployment or hardware the software is to be installed on.  Ohhhh it’s for a Macintosh… lol.  Well hopefully not that bad, but you get the point.
  23. No naming style or code conventions.  Honestly it doesn’t matter what you use… as long as you are consistent with the rest of the team, and hopefully at least yourself.
  24. Using global variables everywhere.  These are NOT your friend and hog memory like nothing you have ever seen before!
  25. Not asking for help at all during the software development process.  If you’re stuck, don’t fight with it for hours on end!  Ask for help!
  26. Not commenting your code.
  27. Hogging all information to yourself.  You think you’re more valuable this way?  You’re actually not and there is a plan brewing to get you kicked off the development project, and possibly out of the company.  You might want to brush up your sign “Will code for pizza!”.
  28. Performing database operations at the application layer instead of the database layer. Not only is this putting the processing juice on your application instead of your server, but you have put your database at risk of data integrity issues, and getting bad data!  Some of my hipster cool friends are always saying “It’s alllll good”, well, if your database can be caught saying this… and If everything looks good to your database, then you should be worried.  It is NOT all good!
  29. Not validating your data! Yikes…  Yes.. let’s just assume all the data is perfect! NOT!
  30. No load testing.  What.. This is supposed to run on 1,000 user’s machines through Citrix?  Interesting… Shouldn’t be an issue! lol… NOT.

Software development is tricky enough!  Make it easier on yourself by ensuring you do not make any of these mistakes.  Although it seems like a simple list of things not to do, it can make your life so much easier! By the way, while you’re here, check out our competition to win a free iPod, we are trying to get a software development blog as the number 1 site on Technorati!  All you have to do is add this blog as a favorite, and we will pick a winner as soon as we are number 1! Wouldn’t it be cool if the number 1 Technorati Blog was a software development blog with real content instead of “Boing Boing”, or “How To Make Money Online”?  Help me out!

The One Minute Software Development Manager

Posted in Porject Management, Software Development, Software Development Manager with tags , on Tháng Hai 20, 2008 by hadv

Being a Software Development Manager is a great job, if you are the right person for the job.  You have to have a real passion for technology and leadership to excel in this role.  I have spent the better part of the last 5 years studying leadership and software development, and have really enjoyed the journey.  Below are some of the key things I try and focus on day to day as I interact with my team.  Hopefully some of these points can help you!

Set Clear Goals

Setting clear goals is a key role of a Software Development manager.  This means that just telling your team “Can you get project xyz done by Friday, thanks!” is not enough, in fact, it’s useless!  You need to be able to clearly define the goal, and then describe the goal to your team in beautiful clarity!  This is done both on paper, and in meetings for visualization of the goal.  The clearer you can make the goal to your team, the more likely they will be to achieve the goal, and surpass it!  Most goals are made up of mini-goals, or mini steps if you will.  Once you have clearly defined the goal, you need to be able to setup the game plan for the goal, filling in the steps to get the goal achieved.  Once your goal is defined in minute detail, you are set!

Lead By Example

There is nothing worse than working for a manager that barks orders all day long, and yet is never around when you need them.  If you expect your team to come in on time and be totally devoted to the job, projects, and goals at hand, you have to be the most on time, focused individual of the team.  If you expect your team to take amazing meeting minutes, keep meetings focused, and send awesome project status reports, then you need to ensure you are the best meeting minute taker on the team, creating action item reports, and detailed, easy to read, meeting minutes.  During crunch time in a project, you need to not only have people are willing to come in on weekends, and put in the extra effort, you need to be the main resource available during these times!  You need to practice what you preach, set examples, and share in all the hardships.  Nobody wants to work for a manager that just wants to revile in his teams accomplishments, without actually helping the accomplishment happen!

Set Clear Direction and Vision

As a leader in your organization, your main goal should be to set the vision for the team, and do it in a clear and concise way!  It’s not enough to simply send an email that says “Our vision is to create great bug free software fast!” that is pretty much useless.  What you need to do is make your team live, breath, and act the vision.  You need to be able to energize your team to follow the vision that you create, and have a clear roadmap on how each member of the team is helping the vision take shape.  You also need to be up to speed with the rest of company, and be ready to update the team vision when it’s necessary.  Especially in the current speed of the business world, you need to be ready to react, and move that ship in another direction when needed.

Motivate Your Team

Motivation is key.  Nobody wants to work for someone that does not motivate them.  But how do you motivate a team.  It is actually easier said than done.  Take interest in your team, learn about your team, involve them in decision making and make them feel special.  Listen to your team when they have something to say.  When they come to your door and want to talk, always make time for them.  Have a lot of energy, get your sleep, eat healthy, and exude energy at every meeting, and every interaction.  You need to connect with every person on your team in a different way.  See, different people are motivated by different things.  If you get to know them on a personal level, you will find out exactly what makes them tick, and how you can make them happy, and motivated.  The more your team is motivated, the higher the retention of the individuals, and the more they will be able to contribute to your organization.

Focus On What Is Important

One of the single most important things you can do as a Software Development Manager is focus on what is important.  There will be distractions coming at you and your team on a daily basis.  You need to have the ability to quickly and easily avoid these distractions and lead your team to the important tasks at hand.  Your team needs a beacon of light, a light house.  You are the lighthouse of the team.  Your team could be the most powerful, smart, energetic team on the planet, but if you are not focusing them on what is important, they will fail!  The effort that your team puts into the job is very important, but if they are putting all their time and effort into solving the wrong problem, or the wrong problem the right way, they are wasting their time!

Be the Most Positive Member of the Team

Negativity kills!  Both literally and scientifically!  Negative thoughts and emotions have been proven to cause your immune system to weaken, and a big contributor to disease and death.  Is it any shock that this same attitude in the work place slows down projects, and causes more bugs in software than are necessary!  There are certainly times when feedback and criticism needs to be given to projects and teams, however there is a right way and a wrong way to do this.  Think about this for a second:  Why are people drawn to leaders in the first place?  Because of their negativity?  No.  It is because of their ability to look at negativity and challenges straight on and be extremely positive, and able to find solutions.  Great leaders add life to projects through their positive attitudes, and make teams achieve things that other, even more experienced teams, could never dream of achieving.

Be Decisive and Action Oriented

In order to be a great Software Development Manager, you need to have the ability to think carefully, and make decisive decisions quickly.  You need to be able to take action and carry out the decisions you have made without looking back.  While you are taking action, you also should not have your blinders on, and should be able to ask for feedback every step of the way.  Should the feedback be negative, or not the result the wanted, you have to be quick to change direction if needed, and try a different approach.

Provide the Best Tools

Providing your team with the best tools available not only makes them more productive, and makes your team enjoy their jobs more by having cool toys, it also tells your team that you know their time is valuable!  It shows your team indirectly that you realize that their time is precious, and that they are great assets to the team that cannot be wasted.

Provide the Best Hardware

How long does it take your developers to build their applications, debug, and run multiple tools they run?  Do they have one monitor that they are forced to cram all of their applications on to, and switch between applications all the time to see what one has for output?  How much are you paying them, and how bored are they getting wasting their time with this?  Do everyone a favor, including the company you work for and make sure they have the best hardware you can buy.  Especially with the cost of hardware these days, there is no excuse to waist hours a week for no reason, to save a few hundred bucks.

Trust Your Team and Their Judgement

Everyone on your team has been selected for a reason.  If you are not able to trust them and their judgement, they should not be on your team.  The reason you hire people that are experts in certain areas is so that you can trust them, and because they are just that, experts in their area.  I’m not suggesting that you just let a new person run the show and trust them instantly that would definitely be a huge mistake.  But as a manager you should get to know your team really well over time, and be able to know who are your experts, which areas they are experts in, and when you can, or cannot trust their judgment. For example if you have a masterful DBA working for you, that has built thousands of database designs in his career, would you go sit by him and micro-manage him and tell him what to do, and where to add index’s and how you would like the database structured?  Of course not… So why do so many managers insist on micro-managing?

Be the Coach

I’ve always viewed myself as the coach of the team, and not a manager. You need to be able to find the right talent, and keep them interested.  As a coach you have to be ready to make the plays, and provide feedback on the last period of play!  What was done wrong, what was done right?  Get to the point quickly, give the feedback, make the changes, and try again if there were mistakes made.  If things are going well, still provide feedback and coaching!  You always want to be improving the team!  You want to try and get your team running to its fullest potential.

So there you have it! My One Minute Software Development Manager guide to running a Software Development team!  Good luck, and enjoy the journey!

How To Finish A Big Software Project And Be The Hero

Posted in Porject Management, Software Development with tags , , on Tháng Hai 20, 2008 by hadv

 

We’ve all been there! The huge beast software project that just won’t end/die. In fact Microsoft is constantly getting themselves into this trouble. Vista, SQL Server, XP, all became these huge projects, that in the end, had to have massive features cut, and new leaders appointed to save the day and ship products! At the end of the day, if you are constantly building and building, and never shipping, you’re sunk! How do you get a big software project out of the water and become the software development hero? I’ll tell you how…First, a little history to how the big nasty project starts! A huge software development project is dreamed up to solve some complex problem. Great, that’s what software is all about! But things start going bad right on day one! How?Well, the managers and executives decide that they are going to plan every detail of the software project to the most minute detail. They then assign a project manager to manage all the developers and let them start building each piece independently one-by-one. A few weeks before shipping, the project managers try and combine everything, and all is well right? Wrong… Disaster! The project is delayed! Days pass, weeks, months, years! What the *beep* just happened here! What to do?

It’s Like Building A Building

Have you ever seen the construction of a building? Does everyone go into their own little silos and build their own thing? No! How is a skyscraper built? First lay the foundation, then put in floors, with the elevator shafts, then build floor after floor, then the interior, etc. Could you imagine what would happen if every piece was built in a different site, and then later everything was dropped off at the construction site to be assembled? Even if you had the best plan to assemble everything together, you would have problems! Things wouldn’t fit and would have to be re-done, architects would change their minds, pieces would be missing, and the building would look like a bunch of match sticks!

Be The Software Hero, Finish That Project

Does your software project feel like a disaster waiting to happen? Is it already a disaster? Are you ready to get the software project on track? Here we go…

  1. Source Control
    Do you have a source control system? If you don’t, that is a major problem! Get one ASAP. Without source control you might as well go play Russian roulette. You can’t rollback changes, you have no backups of your source code, you have no history, and it will be nearly impossible to set up proper continuous integration!
  2. Continuous Integration
    Do you have a continuous integration server setup? You know how every time you check in code, and you get the build master to build your code, everything blows up? That’s because he is only making builds when told, and this is probably not often, let alone every time someone checks in any code. Continuous Integration will automatically build your project, and give you the results of the build. You can even add Unit Tests, Coding Standards Tests, etc. But let’s keep it simple to get you on track!
  3. Bug Tracking System
    Without a bug tracking system you have no way of knowing where the quality of your software stands easily. At any time you should be able to see which features are being built, tested, approved, troublesome, etc. If you are relying on excel lists or written notes, invest the money in a bug tracking system as soon as possible!
  4. Patching System
    I’m not going to get into installer issues here, but you need a patching system. You do not want to deploy installs upon installs to your testers.
  5. Disable Untested Features
    Turn off every feature in your application that has not been completely bug tested and approved by your users. If your project is in trouble, you have hundreds of features implemented at 80%, and you probably think they are at 90% – 95%, but they aren’t.
  6. List Major Features
    Make a list of all the major features that are involved in the software project. Start at a very high level. This is the key step to start turning around the project. You are going to pick your battles here, small, winnable battles, instead of fighting a never ending battle with thousands of features.
  7. List Top 20% of Major Features
    Ok so you have a list of all the major features, now take 20% of the high level features and make another list of those. These are the features that must be implemented for a great pre-release version of your software.
  8. Detail Out Top 20%
    For the 20% List, make another detailed list of every feature that needs to be implemented in order for these 20% items to be completed. Rank these features by importance. I like to choose the most complex ones first, and end with the easier ones. This makes it easier to know if you are on track, as finishing easy features first, won’t really give you any indication as to how much longer you are going to take.
  9. Plan The Week
    Carefully figure out which of these features you can complete in the next week. Assign out features to developers on the team. When you assign them, try and keep similar features together. Make sure everyone is checking in code regularly. When they check in, if they break the build, they must fix their build immediately!
  10. Create Branch
    Using the source control system you chose, create a branch. Your goal here is to create a branch, label it as the testing version, and then release a patch in the next step. Next you start working on the items for the next week, while your testers test.
  11. Build Release for Testers
    Get your Build Master into high gear; have him build a patch for your internal quality assurance team.
  12. Testers Take Flight
    Hopefully you have a Quality Assurance Team, if you don’t start with at least one person and get them setup with the Bug Tracking System. Get them to get the patch as soon as it’s available, and get at the testing! By the way, if you can include customers or end users in your quality assurance team, do it! As soon as your testers find any bugs, issues with implementation of features, etc. make sure they report them to the developers! If you have a good bug tracking system, the system should automatically email the developers when your testers give feedback or change the status of bugs.
  13. Software Developers Work on Trunk
    While your testers test, your developers keep working on next week’s items. As bugs come up, they go back to the branch, resolve the issues, and go back to Trunk Development.
  14. Approve Patch
    Your testers have completed the testing? Everything looks good? AWESOME! You have just completed your first set of features that are now ready to be installed! Technically, if you have followed the procedures outlined above, a customer or client tester should be able to install this software, get the patch, and use it!
  15. Continue Steps 9 to 14
    Continue your efforts over and over until you get the 20% done, hopefully this is not as far away as you think!

Your goal is to focus on small features, get them done, and send out a release for testers. This is a huge shift from trying to complete 100% of your bug ridden huge project.

Your team will be extremely motivated to be releasing workable software every week! They will actually speed up, and the whole project will start gaining unbelievable momentum!

When testers find bugs, your developers will fix them faster because the code they wrote is fresh in their minds! If features need to be tweaked and changed, it gets caught early, and changes are much more fluid!

Your business users will start seeing results! They will in turn give you more resources, better tools, and more respect! The shiny happy people will hold hands!

Is there a lot to do? It depends in how much of a mess your development lifecycle is. If you have nothing of the above setup, you are going to have a tough time, but if you focus and execute quickly, you should have no problem’s setting up the ideal environment quickly.

Enjoy being the Software Development Hero!

Tomcatのセキュリティとリスクの基本

Posted in Java, LightWeight J2EE, Security, Tomcat on Tháng Hai 4, 2008 by hadv

前回までで、Tomcat 6系に関する機能や設定、運用といったところに触れてきました。今回と次回は2回に分けて、いよいよTomcatを運用していくに当たってのセキュリティ面に着目していきたいと思います。

Tomcatのセキュリティとリスクの基本

.NET開発者のためのDI&AOP入門(前編)

Posted in .NET, AOP, DI, Seasar on Tháng Hai 4, 2008 by hadv

 “DI”や“AOP”というキーワードを耳にしたことがあるだろうか。これらのテクノロジは、.NET技術者にはまだまだ普及していないのが現状 だが、Java開発での長年の利用結果から見ても開発生産性を飛躍的に高めてくれるテクノロジであることは間違いなく、.NET開発でも必ず役立つもので あり、むしろ使わない手はない。従って、できるだけ多くの.NET開発者にこれらのテクノロジの良さを知っていただき、有効に活用していただきたいと筆者 は考えている。

 そこで本稿では2回にわたり、前編でDIを、後編でAOPを紹介していきたいと思う。本稿を通して.NET開発におけるDIとAOPの有効性と可能性を感じ取っていただければ幸いである。