Just another technology blog!

Random thoughts, tutorials, observations on Java/Web related technologies

  • Blog Stats

    • 1,450 hits
  • Category Cloud

  • My Del.icio.us

  • Subscribe

A tiny little bash script to ensure if your tomcat server started successfully

Posted by Stephen on October 8, 2009

Not the best solution in the world, but works fine for Tomcat.6.0.18….

# Script polls tomcat log and checks if it started properly

# loop forever
while [ 1=2 ]; do

# grep tomcat’s catalina.out for "INFO: Server startup" text
grep "INFO: Server startup in" /home/tomcat/logs/catalina.out > a.txt

# if found then exit
if [ -s a.txt ] then
echo "Tomcat started"
exit 0
fi

# if not found, just print a message and sleep for 10 seconds
echo ‘checking catalina.out for status [INFO: Server Startup in] every 10 seconds until completed’
sleep 10

done

Posted in Java | Leave a Comment »

Continuous Integration with Hudson, TeamCity

Posted by Stephen on October 8, 2009

This was an interview question for me two jobs ago: “Have you heard of Continuous Integration?” – my answer was “No sir, but the project I worked on was a large scale integration effort and I have been involved in some serious technology & team integrations rather continuously – is that close enough?”.

The interviewer said – “no, that’s not that, if you haven’t heard of it then you should look into it”.

And now – two jobs later. I have been involved in setting up some form of CI process for my current and past two projects. I have to say, I’m a big fan of the whole processes now. I can’t imagine any projects these days running without some sort of CI

Here’s the definition by Martin Fowler the UML guru:

Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily – leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly. This article is a quick overview of Continuous Integration summarizing the technique and its current usage.

(If your project doesn’t have a CI you should seriously consider adding it. It’ll keep your code cleaner, your product much better. More than that, it’ll make your life and the life of every one involved in the project so much easier.)

I have worked with a couple of products so far – JetBrain’s TeamCity and Hudson.

Hudson is completely free – it’s simple & straight forward. Easy to manage configurations, and the whole concept is rather simple. Very easy to get it up and running in no time. Team City on the other hand is from JetBrains. I have heard intelliJ from JetBrains is the best IDE in the world, but I haven’t had a chance to play with it yet. I can’t speak for intelliJ, but I can really speak for TeamCity.

TeamCity is just awesome. The product description goes like this “Distributed Build Management and Continuous Integration Server” (we techies love all things distributed, yes). The product comes with a free and commercial version, the free version supports 3 build agents (for distributed builds) and 20 users. For small teams this is good enough.

The best part about TeamCity is it’s Eclipse plugin and the RemoteRun feature. The plugin lets you select a subset of files you have updated since your last checkout and submit them for a remote build run – the server “does a fresh checkout of the entire code base, overwrites the files you submitted and runs through the compile/test, etc”. And all the while you could be watching the live server logs in your Eclipse plugin – life can’t get any better than this.

I am using Hudson now and I like it so far. One small limitation – it doesn’t let me checkout two projects from two different branches. The only way of doing this is through two separate projects one lined up after another, or use command line checkout using the “Execute shell” option. The documentation says Hudson is also a Distributed server, but I haven’t configured Build agents so I can’t speak for it. Any one has any experience on this?

Anyways….. Go Continuous Integration….

Posted in Continuous Integration, Java | Tagged: , , , | Leave a Comment »

AppFuse & SpringFuse

Posted by Stephen on July 19, 2009

AppFuse - http://appfuse.org/display/APF/Home

I have been using AppFuse for a little over a year and it is one of my favorites.

If you are in the OpenSource side of things and you are working on Java related technologies then I’m sure you must have stumbled on Matt Raible’s blog.  I have found a lot of good info there. Matt the Java Web/UI Frameworks Guru made this AppFuse app to make our lives much easier.

Quoting Matt:

AppFuse is an application for “kickstarting” webapp development. To learn more about AppFuse and why you should use it, see Seven simple reasons to use AppFuse at http://www-128.ibm.com/developerworks/java/library/j-appfuse.

Getting started with open source tools for the Java™ platform such as Spring, Hibernate, or MySQL can be difficult. Throw in Ant or Maven, a little Ajax with DWR, and a Web framework — say, JSF — and you’re up to your eyeballs just trying to configure your application. AppFuse removes the pain of integrating open source projects. It also makes testing a first-class citizen, allows you to generate your entire UI from database tables, and supports Web services with XFire. Furthermore, AppFuse’s community is healthy and happy — and one of the few places where users of different Web frameworks actually get along. (https://www.ibm.com/developerworks/java/library/j-appfuse/)

That’s an article from 2006. And I think AppFuse must’ve improved a lot from then. To learn Java web frameworks this is a very handy resource – to get the AppFuse running in any suuported technologies it usually takes less than 5 mins. (http://appfuse.org/display/APF/AppFuse+QuickStart)

Now, that’s AppFuse – about SpringFuse a little later…

SpringFuse – http://www.springfuse.com/index.action

I recently came across SpringFuse. At first glance – erghhhhh – another code generator tool, time to run…. but then the site said it generates code for “SpringMVC”, “SpringWebflow”, “Spring Security” – well that got my attention. After following their tutorial, some 15mins later – I was running the app locally and looking through the generated code – I have to say SpringFuse litreally blew my mind….

Posted in Java | Leave a Comment »

The m2eclipse + WTP problem !

Posted by Stephen on July 19, 2009

If you are fighting the m2eclipse + WTP battle and landed here there’s hope – don’t give up…

WTP has become the de facto standard for “Eclipse + Tomcat” development, it’s super easy to configure, the HOT SWAP works like a breeze – nice shortcuts to publish, run, stop servers (Ctrl+Alt+P/R/S), all nothing but nice & easy !.

M2Eclipse is a nice maven plugin. I didn’t like the earlier versions like a year ago, but now the plugin looks some what bug free and works smoothly. (I tried one other plugin IAM and it didn’t look better than m2)

Now, enter the M2Eclipse + WTP – you are a dead man… especially if you are trying to find out why your big multi module maven project that works so nicely when you do a “mvn package & WAR deployment” throws all kinds of errors in WTP.

Here’s what I found after a lot of googling – Eclipse build doesn’t run “mvn resources:resources” goal which replaces the resource file parameters “${xyz,abc}” with actual values. So, now your properties file are sitting in your classes directory with ${xyz.abc} with no actual values – hence the errors.

These links suggest possible solutions for this problem:

http://cmaki.blogspot.com/2007/10/getting-maven-and-eclipse-to-work.html

http://www.jroller.com/eu/entry/maven_resource_filtering

But unfortunately, both of these solutions didn’t work for me because I was getting some errors related to configuring external builders. But because I understood the root of the problem, I managed to come up with a different solution – to define an “External Tool Configuration” with the right “Build” and “Refresh” settings – see below. This works perfectly !!

I. Create an External Tool Configuration – Select your root POM project for Working Directory..

II. Set Build before Launch, this actually kicks off the Eclipse Builder before Launch – and this option builds the entire workspace

III. This is the key – Refresh the entire workspace upon completion – this brings in all the classes directory with the replaced property values into Eclipse IDE which WTP uses.

Posted in Java, Maven2 | Tagged: , , , , , , , , , | 4 Comments »

TheLadders (job site) did an article on me

Posted by Stephen on July 13, 2009

Around March this year I was laid off, but by God’s mercies I was employed in a month time. TheLadders was one of the job sites I used to post my resume. After I found a job they had asked me to share my story – so I wrote them a short email. They liked my story, Patty Orsini (one of the editors at ladders) called me to get all the details of my job loss and job hunt. And three weeks later they published this article and sent it to all their ladders members as part of the weekly digest.

First time I’m on a article………… :)

If you actually make it through the end of the article and are wondering what I built – well its a maven app that demonstrated all the technology things that my employer was interested in. I don’t mind sharing the app or more details with you if you are interested – just leave a comment…

Skype Job Interview Pays Off

Skype Job Interview Pays Off

Java developer Stephen Bhadran moved to Florida for one job that dried up. He won a new job in Los Angeles literally by phoning it in. (by Patty Orsini)

When Stephen Bhadran took a job as a Java developer with a Florida startup in July 2007, he was excited about the opportunity. He moved his family from Los Angeles to Florida and dove head first into the work.

“It was a small company, but they were going to build a big product,” he said. “It was going to be something that would compete with Google. It was very exciting. The company had a little money, they hired smart talent. I was one of 40 developers.”

But within seven months the company’s Web site started losing traffic, revenue went down and the company started laying people off.

“I survived the first round,” he said. “But if you have one layoff, you’ll have another one. I was laid off on March 17.”

Bhadran said that even though he knew being laid off was a good possibility, he didn’t start looking for new jobs until his layoff became certain. He had always had good reactions to his resume. But in the current economyin March, that wasn’t the casethings didn’t go so smoothly.

“I used to put my resume on Monster, and I would get a lot of hits. But in March, I had just 10 hits, and I was getting worried,” he recalled. “There are so many resumes on the job boards, employers are not finding them in searches, they are not even looking at them, because there are thousands of them.”

His search on Monster also proved that Florida was not the best place to be looking for a job. “I went to Monster, and got seven listings; six of them were not Java related,” he said. “I saw one or two Java positions in Miami; in Dallas and Los Angeles, there were about 150 each. That’s when I decided Florida is great as long as you have a job, but it’s hard to find one in this market.”

That’s when Bhadran became a TechnologyLadder member. “The jobs on TheLadders paid better, and they had the type of jobs I was looking for. I thought I’d get noticed there.”

Bhadran also utilized used LinkedIn in his search. After he lost his developer job in Florida, he asked supervisors, project leaders and senior management to write recommendations, and loaded his resume onto the site. “Anyone who opened my resume saw all the references,” he said. “I think that really helped.”

Bhadran knew he was up against stiff competition for the job. “There were 13 of us laid off from my previous job. Everyone was sending resumes, so I decided to build a small Java application. I didn’t launch it, but instead, I sent it with all my applications, with instructions on how to run it, so employers could get a sample of my work.”

One of the places he sent his resume was the University of California at Los Angeles.   The university had a contract position for a Java developer , and liked what they it saw. But, even though the recruiter thought he was a good fit, UCLA would not fly Bhadran to Los Angeles for an interview. Bhadran said he told them, “‘I can do the interview on Skype.’ And then I gave them a demo of the app that I had built, and they were able to watch it, and they were pretty happy with it. I explained to them how I built it, and told them it took me only three days; it showed that I could quickly build apps, and that was a great selling point.”

In early April, Bhadran was offered the position of principal system analyst at UCLA. It’s a nine-month contract position, but he’s hoping he can once again impress them with what he can do, and extend his tenure.

“I shared my idea of building an app to show potential employers with all my colleagues,” he said. “If all they are doing is sending a resume and writing cover letters, everyone is doing the same thing. This was different, and it’s what got me the job.”

Posted in Java | Leave a Comment »

Glassfish vs Tomcat

Posted by Stephen on June 25, 2009

I’ve read in a few articles and blogs that Glassfish is better compared to Tomcat even though it’s not as popular as Tomcat.

Well, today I got an email from the Sun communications titled “Glassfish for Tomcat Users” and it had a link to this comparison report: https://www.sun.com/offers/docs/GlassFish_Tomcat.pdf

Here’s the table from the pdf:

Feature Tomcat GlassFish v2 GlassFish v3 Prelude
Tomcat valves X X X
mod_jk support X X X
Webdav support X X X
CGI support X X X
Tomcat bug fixes X X X
Java EE certified X
Servlet 2.5, JSP 2.1 X X X
JSF 1.2 X X
Metro Web Services stack (.NET interoperability) X X
jMaki (AJAX framework) X X
Jersey/JAX-RS 1.0 (RESTful Web Services) X X
Sophisticated Admin console and CLI X X
JMX X X
Node Agent and Cluster Management X
Upgrade Tool X
Application client container X
Java Webstart support X
JDBC Connection Pooling X X X
JTA/JTS X X
J2EE Connector Architecture 1.5 X X
Native jRuby/Rails deployment—no need for servlet container X
Dynamic resizing of jRuby Runtime Pool X
Rapid redeployment—maintain session state on redeploy X
Update Center X X
Verification tools X
Image Packaging System (IPS) tools X
Grizzly (Java NIO) X X
Comet (HTTP Push) X X X
CORBA X
Modular architecture based on OSGi X
Embeddable Server X
Centralized admin of load balancer plug-in X
High availability X
In-memory compilation of JSPs X X
Integration with Identity Manager, Access Manager, Registry Server, and Java Business Integration X
Superior admin support for clustering and load balancing X

I’m not sure if the long list of Xs for the Glassfish means anything here, here’s why:

  • Tomcat does have JMX implemented (link)
  • I’m pretty sure you can use JSF/jMaki/JTA/JCA/OSGi (or any other technologies/libraries for that matter) inside Tomcat just by including the right dependencies in your application
  • One of the Tomcat 6 connectors is NIO based (link), may be not Grizzly NIO but it is for sure NIO based [filip hanik who implemented it is now at Spring Source - probably tweaking the Connectors for  tm/dm servers]
  • About “Java EE Certification” – yes Tomcat don’t do EJBs, but the question is – is any one still doing EJBs?
  • Tomcat’s clusterning/load-balacing are not too difficult to configure – yes, it lacks admin console but once setup those things work fine

So IMHO if the Sun guys are trying to sell me Glassfish – this is a lame attempt. I’d like more technical details and may be actually see some numbers….

I’m yet to try Glassfish though, I’m sure I’ll love it – but not today !

Posted in Java | Tagged: , , , | 5 Comments »

A Spring Security week !

Posted by Stephen on June 19, 2009

A Spring Security week for me !

We have a Java Work Group in my work place, and last month I volunteered to do a presentation on Spring Security. Spring Security is a behemoth now. The most recent download (v 3.0.0M1) had the product documentation at 200+ pages. This session was just to give every one an overview. I used a number of sources to put this together, it’s all listed in the last slide. Ben Alex’s video presentation was extremely useful to understand the concepts…

Posted in Java, Spring | Tagged: , , , , , , | Leave a Comment »

Brief overview of Maven, Archiva, Subversion and Team City

Posted by Stephen on June 10, 2009

Last week was fun…

I setup Continuous Integration for my project using Team City. The project source is in Subversion and it’s a Maven project, so that was pretty easy to configure in Team City. Also had to install a Repository Manager Archiva to host maven dependencies. Team City is just awesome, can’t say enough about it. I did briefly look at other CI server products, but nothing as slick and team city.Team City’s “Remote Run” is THE feature any developer could ask for.

When all is done, I even prepared a little presentation with a brief overview of all the tools:

A disclaimer about the presentation: All (or most) of the images or text are either from product documentation or other articles I gathered.

Posted in Continuous Integration, Java, Maven2 | Tagged: , , , , , , , , , | Leave a Comment »

Google wave !

Posted by Stephen on June 2, 2009

Catch the new wave @ http://wave.google.com/ (this one comes all the way Australia).

Google is making this Open Source to foster innovation and adoption among developers. I’m sure developers are already lining up to build something with it, but I don’t know if this will catch up in the enterprises as many of the articles say. The features look amazing though, I particularly liked the “collaborative real-time document editing” and “playbacks” which could be very useful in enterprises.

Only problem with this presentation is it’s 90 minutes long. I wish they had made another comic book for this like when they released Chrome (Chrome Comic), that was one exciting release. If you want to cut to the meat of this presentation here’s some help, move the video time slider to the minute and watch just what you like:

7th      to  15th  minute    -  Basic Wave demo with 3 of them editing a wave at the same time

18th    to  22nd minute   -  Embedding Wave in a Blog site (google’s blogspot)

23rd    to  25th minute   -  Embedding Wave in a Social Networking site (google’s orkut)

25:30  to  27th minute   – Wave from an Android and iPhone

28th     to  33rd minute  -  Collaborative in-line editing with playbacks (my favorite – this could be extremely useful in IT)

….and then they move on to the client and server side extensions which are also pretty cool.

I found this article to be good, it summarized all the innovative features very nicely: http://mashable.com/2009/05/28/google-wave-guide/

Posted in Google | Tagged: , , , , , , , | Leave a Comment »

Tomcat Remote Deployment using Maven2 & Cargo

Posted by Stephen on May 27, 2009

Gone are the days when you have to copy your WAR into Tomcat/Server’s Webapp directory or use the Tomcat Web UI Admin module to deploy your WAR. With Maven2-plugin-Cargo the deployment becomes one simple maven command.

Add this to your pom.xml :  (NOTE – This setting works only for Maven2 and Tomcat6x)

<build>
  <plugins>
    <plugin>
      <groupId>org.codehaus.cargo</groupId>
      <artifactId>cargo-maven2-plugin</artifactId>
      <configuration>
        <wait>false</wait>
        <container>
          <containerId>tomcat6x</containerId>
          <type>remote</type>
        </container>
        <configuration>
          <type>runtime</type>
          <properties>
            <cargo.hostname>${cargo.hostname.dev}</cargo.hostname>
            <cargo.servlet.port>${cargo.servlet.port.dev}</cargo.servlet.port>
            <cargo.tomcat.manager.url>${cargo.tomcat.manager.url.dev}</cargo.tomcat.manager.url>
            <cargo.remote.username>${cargo.remote.username.dev}</cargo.remote.username>
            <cargo.remote.password>${cargo.remote.password.dev}</cargo.remote.password>
          </properties>
          <deployables>
            <deployable>
              <groupId>Your.Maven.WAR.Project.groupId</groupId>
              <artifactId>Your.Maven.WAR.Project.artifactId</artifactId>
              <type>war</type>
            </deployable>
          </deployables>
        </configuration>
      </configuration>
    </plugin>
  </plugins>
</build>

<properties>
     <!-- remote deployment properties -->
     <cargo.hostname.dev>Your.Tomcat6x.Server.Hostname(YourTomcat)</cargo.hostname.dev>
     <cargo.servlet.port.dev> Your.Tomcat6x.Server.PortNumber(8080)</cargo.servlet.port.dev>
     <cargo.tomcat.manager.url.dev>http://YourTomcat:8080/manager</cargo.tomcat.manager.url.dev>
     <cargo.remote.username.dev>admin</cargo.remote.username.dev>
     <cargo.remote.password.dev>admin</cargo.remote.password.dev>
</properties>

And run the following commands from your project root directory (where pom.xml is located) :

  • mvn package (ensure that the war file is created under the target directory)
  • mvn cargo:deploy
  • mvn cargo:redeploy
  • mvn cargo:undeploy

<build>

<plugins>

<plugin>

<groupId>org.codehaus.cargo</groupId>

<artifactId>cargo-maven2-plugin</artifactId>

<configuration>

<wait>false</wait>

<container>

<containerId>tomcat6x</containerId>

<type>remote</type>

</container>

<configuration>

<type>runtime</type>

<properties>

<cargo.hostname>${cargo.hostname.dev}</cargo.hostname>

<cargo.servlet.port>${cargo.servlet.port.dev}</cargo.servlet.port>

<cargo.tomcat.manager.url>${cargo.tomcat.manager.url.dev}</cargo.tomcat.manager.url>

<cargo.remote.username>${cargo.remote.username.dev}</cargo.remote.username>

<cargo.remote.password>${cargo.remote.password.dev}</cargo.remote.password>

</properties>

<deployables>

<deployable>

<groupId>Your.Maven.WAR.Project.groupId</groupId>

<artifactId> Your.Maven.WAR.Project.artifactId</artifactId>

<type>war</type>

</deployable>

</deployables>

</configuration>

</configuration>

</plugin>

</plugins>

</build>

Posted in Maven2 | Tagged: , , , , , , , | Leave a Comment »