Prabhu Kumar

a tech twaddler..

Creating a simple java web app using IntelliJ IDEA and setting up remote debugging

without comments

I had to get this setup up and running at work, thought it’ll be a good idea to jot it down here. The first step is to install IntelliJ IDE from here. I installed the ultimate edition which has a free 30-day trial, but the steps below should work well with the free community edition as well. We’ll be hosting the app on Tomcat server (running on a remote machine) so go ahead and install it from here. I installed version 8 using the windows service installer. And of course, since you’re developing a java app make sure you have the jdk installed.

Launch IDEA and create a new project, we’ll call it SimpleJavaWebApp. Select Java Enterprise and Web Application. Make sure the project SDK is set correctly and application server is set to the version of Tomcat you installed.

image

Let’s add a Java servlet to the project. Right click on the src folder in project explorer and select New –> Servlet, give the servlet a name and add it to the project.

image

Open MyServlet.java and copy paste the below code in the doGet() function,

If you are seeing an error which says “java: try with resources is not supported in –source 1.6”, go to project properties by right clicking on the project and selecting Open Module Settings, select Project on the left rail and change the Project Language Level to 8.

Let’s modify index.jsp to put an entry point to our servlet,

Modify web.xml file and put the below servlet configuration in it, the url pattern is case sensitive so make sure it matches your servlet name exactly,

Go to Build –> Rebuild Project, and make sure the project is building fine. Let’s now package our application in WAR format (Web application ARchive) and deploy it on a machine running Tomcat.

Right click on the project and select Open Module Settings, click on Artifacts on the left rail and select + to add a new artifact type. Click on Web Application : Archive and select the project name.

image

Now when you build the project you will find file SimpleJavaWebApp_war.war generated under \SimpleJavaWebApp\out\artifacts\SimpleJavaWebApp_war folder.

Let’s deploy our app now, go to the machine where you installed Tomcat (it could be the same machine too), and under the Tomcat installation directory, copy the above WAR file under the webapps folder. For me the path is “C:\Program Files (x86)\Apache Software Foundation\Tomcat 8.0\webapps”. To make sure your app is working as expected, navigate to http://localhost:8080/SimpleJavaWebApp_war/ and check if the web page loads up correctly.

image

So the bulk of the work is done. We’ve created a simple Java web app, added a java servlet to it, deployed the application on Tomcat and made sure that the servlet code is invoked correctly. We’ll now look at how to remotely debug this app. This is useful is cases where you have the application running on a server, and your code and source enlistment are on a different machine.

To get remote debugging working, we need to instruct Tomcat to start the JVM in a “debug” mode and then attach to the JVM from IDEA.

Open Tomcat server properties, go to the Java tab and add the below entry under Java Options (make sure you add this in a new line),

-agentlib:jdwp=transport=dt_socket,address=1043,server=y,suspend=n

image

Restart the server and check if you can access SimpleJavaWebApp from a remote machine. I setup the server and deployed the war file on a different machine and navigated to below URL to check,

image

We now need to create a debug configuration in IDEA to connect to this machine. Go to Run –> Edit Configurations… Click on the + icon and add Tomat Server –> Remote configuration. Make sure you specify the host IP address correctly. You can also modify the ‘Open Browser’ option so that the java app launches when you start debugging.

image

Switch to ‘Startup/Connection’ tab and set the TCP port to the one you used while setting up Tomcat, 1043 in this case,

image

Save the debug configuration and set a breakpoint in the doGet() function in MyServlet.java file. Now start debugging. You should see the web browser launch and when you click on the link to invoke the servlet, your breakpoint should be hit.

image

In case you see an error in IDEA which says ‘unable to connect : connection refused’, you might need a firewall exception for incoming connections on port 1043 (and 8080 too). So go to Windows Firewall settings and create an inbound rule on TCP port 1043 to allow incoming connections, and that should fix the problem.

Written by Prabhu Kumar

March 29th, 2015 at 4:48 pm

Hello VS!

without comments

After having worked for AppEx (a.k.a Bing Apps or MSN Apps) for over 3 years, it’s time for me to move on. We shipped the MSN Sports app on pretty much every platform over the last few years, and it was fun all along! Met some great folks in the team, made some amazing friends and got to learn a lot from some of the smartest out there. The next chapter begins at Visual Studio Online, with an exciting new project! It’s going to be hardcore tech and I’m really looking forward to all the fun :-)

Also, this blog could use some updates once in a while ;-)

Written by Prabhu Kumar

March 22nd, 2015 at 10:16 pm

Posted in Uncategorized

Learning By Slipping

without comments

Here’s an old, but still relevant, post by Steven Sinofsky on shipping products,

http://blog.learningbyshipping.com/2013/05/01/learning-by-slipping/

Some excerpts,

“In order to slip you need to know the ship date. When people talk about projects shipping “first quarter” that is about 90 different dates and so that leaves everyone (on the team and elsewhere) guessing what the ship date might be.  A date is a date.  All projects should have a date.  While software itself is not launching to hit a Mars orbit, it is important that everyone agree on a single date.  Whether that date is public or not is a different question.”

“Interestingly, the error rate in short-term, continuous projects can often (in my experience) be much higher.  The view of continuously shipping can lead to a “project” lasting only a month or two.  The brain doesn’t think much of missing by a week or two, but that can be a 25 – 50% error rate.  On a 12 month project that can mean it would stretch to 15-18 months, which does sound like a disaster.”

“When a task cannot be partitioned because of sequential constraints, the application of more effort has no effect on schedule.  The bearing of a child takes nine months, no matter how many women are assigned. The Mythical Man-Month – Frederic P. Brooks

“Quality is the most difficult to manage and why the test leadership is such a critical part of the management structure of any project.  Quality is not something you think about at the end of the project nor is it particularly malleable.  While a great test manager knows quality is not binary at a global level, he/she knows that much like error bars in physics a little bit of sub-par quality across many parts of the project compounds and leads to a highly problematic, or buggy, product.  Quality is not just bugs but also includes scale, performance, reliability, security, and more.”

“Quality is difficult to manage because it is often where people want to cut corners.  A product might work for most cases but the boundary conditions or edge cases show much different results.  As we all know, you only get one chance to make a first impression.”

On the same topic, if you know that you suck at planning and factor this in next time, it might actually prove a little useful ;-)

Written by Prabhu Kumar

February 14th, 2014 at 6:16 pm

Posted in Uncategorized

chirp

without comments

* chirp * chirp *

Written by Prabhu Kumar

December 11th, 2012 at 7:15 pm

Posted in Rant

Get ‘Programming Windows 6th Edition’ by Charles Petzold for $10!

without comments

Programming Windows 6th Edition

O’Reilly has a special offer on the new book that Charles Petzold is working on, Programming Windows 6th Edition. This should be a great book covering Windows 8 app development in C# and XAML.

You can get this book for $10 now (offer lasts till 31st May), and future editions of this book, as and when new chapters are added, will be available to you for free.

Read more at Charles’ blog here: http://www.charlespetzold.com/blog/2012/05/An-Experiment-in-Book-Publishing.html

Shop at: http://shop.oreilly.com/product/0790145369079.do

Written by Prabhu Kumar

May 30th, 2012 at 8:37 pm

Posted in Uncategorized

A festive feel for the 404 page?

without comments

Was just playing around with JavaScript and came across this snowflake tutorial by Kirupa, we have a fancy 404 page now :)

Try this – http://www.techtwaddle.net/404

Snowfall effect – http://www.kirupa.com/html5/creating_falling_snow_in_html_js.htm

Written by Prabhu Kumar

December 18th, 2011 at 4:29 pm

Posted in Development,General

‘CODE’ by Charles Petzold: An absolute must read

without comments

You know how sometimes you come across a book and you go “I wish I had read this years ago!”. CODE is just that book. It’s a book about how computers work and the way in which Charles Petzold flows through the topics is pure artistry. Those electronics class lessons in college would have been much more interesting if I had read this book then ;)

The book starts off with two best friends trying to communicate from across the street using only flashlights. This is how the idea of ‘code’ is introduced. It then takes you through a journey involving Morse Code, Braille and how telegraphs and relays were used to send codes over long distances. For me, the most interesting part is when he starts building logic gates from relays and switches. This lays a solid foundation for things to come. These logic gates are then used to build half-adders, full-adders (using two half-adders), oscillators, flip-flops and latches; finally getting assembled into a unit of Random Access Memory. Towards the end, a simple computer with processing, input and output systems is designed. The book might be a little old but still very relevant.

The most amazing thing about this book? It teaches you concepts at such a fundamental level that your mind will be blown. And before you know it you will be building ripple counters from flip-flops! If you have anything to do with computers go read this book. You won’t be disappointed.

CODE on flipkart

CODE on Amazon

Written by Prabhu Kumar

November 15th, 2011 at 12:33 am

Posted in Uncategorized

My next job

with 9 comments

Today was my last day at Samsung. I completed 3 years there this July. My next job takes me to a new city and my domain takes a 180 degree turn from device drivers and firmware to something more related to the web.

I will be joining Microsoft, Hyderabad as an SDET in the Bing team.

Next monday, 12th September, will be my first day at Microsoft. I’m really excited and I know there is a ton of things for me to learn. Really looking forward to this!

Written by Prabhu Kumar

September 9th, 2011 at 11:20 pm

Posted in General

Hey ma look what I got, gingerbread on my HD2!

without comments

Yep, that video above shows my HTC HD2 running Android Gingerbread (v2.3.4)! I came back home, and not having much to do thought I’ll give android another try. Sometime back I had tried running android from SD card but it didn’t work, later I found out that it was because of an older radio version on my device, so I had to update the radio version to fix it but it all looked like too much trouble and I put the HD2 back in its box. This was 6 months ago.

Today I thought I should take it for another spin. But this time we go all in, erase Windows Mobile 6 and flash the ROM with all the android goodness! It is pretty simple really, all you need is some patience to read all those articles on XDA a little carefully :)

The basic steps I followed are,

  • Check your radio version and update to 2.08.50 (if you’re running an older version)
  • Install MAGLDR 1.13 on your phone
  • Install Clockwork Mod on your device
  • Select an android ROM of your choice and flash. I chose the stock android gingerbread ROM version 2.3.4.

Here are the posts on XDA I referred to androidify my hd2,

http://forum.xda-developers.com/showthread.php?t=893948 (read this fully first, very important!)

http://forum.xda-developers.com/showthread.php?t=1044830

http://forum.xda-developers.com/showthread.php?t=609477

http://forum.xda-developers.com/showthread.php?t=905060 (this is the android rom I installed)

http://forum.xda-developers.com/showpost.php?p=10206031&postcount=2 (faq)

http://forum.xda-developers.com/showthread.php?t=929324 (a list of all the rom’s you can choose from)

To all the guys at XDA, thanks for all the posts and how-to’s for noobs. You rock!

Written by Prabhu Kumar

July 23rd, 2011 at 1:15 am

A quick update: Mango on my HD7

without comments

IMAG0001

This is going to be a quick post. Just over 2 weeks ago I got the Windows Phone Mango invite I was waiting for; my HD7 has been running mango in full glory since then. The installation took a long time but went pretty smoothly, backing the data up takes most of the time. I am really liking the Mango update, this is what windows phone should have been when it launched. Multitasking, IE9, better facebook integration in people’s hub and a plethora of other features. The voice command integration in mango is exceptional, and I find myself using it quite often. Being able to listen to an incoming message, compose a reply and send it, all using only your voice, is really amazing (or magical, as some might call it) and works really well.

Strangely, I am not using the multitasking feature all that much. Somehow I have an obsessive compulsion to keep the backstack clean all the time. Whenever I am done using the phone, I keep pressing the back button just to make sure there is nothing on the stack. I have a feeling I’m not alone.

In other news, AppHub gets some new features and Windows Phone is expanding to new markets. More importantly, Microsoft’s pubCenter, finally, will be available to developers outside of US of A. According to Todd Brix’s post, pubCenter should launch to new markets (including India!) before the end of 2011. I can’t wait to try out adCenter. You can read Todd’s post here,

http://windowsteamblog.com/windows_phone/b/wpdev/archive/2011/07/20/windows-phone-developers-get-new-app-hub-features-mango-app-submission-just-one-month-away.aspx

Written by Prabhu Kumar

July 21st, 2011 at 11:26 pm