Every Flavour Beans

“The time has come…to talk of many [technologies].” –Lewis Carroll(‘The Walrus and the Carpenter’)
Development Tools. Web Frameworks. GNU/Linux. Nokia N800. Video Encoding.

January 20, 2009

“Hello, World” Java Web Application using Java SE 6 + Tomcat 5.5 + Maven 2

Filed under: General — tabrez @ 9:04 pm

See my previous posts to install Sun Java SE 6, Apache Tomcat 5.5/6, Apache Maven 2 on Windows and Ubuntu GNU/Linux operating systems:

Once all the required software components are installed, simply run the following command in the command prompt/shell to generate a basic Java web application project in the current working directory.

# mvn archetype:create

You can also run ‘mvn archetype:generate’ if you want to generate the project in interactive mode. The command will then prompt you for relevant information when creating the project.

# mvn archetype:generate
[INFO] Scanning for projects…
[INFO] Searching repository for plugin with prefix: ‘archetype’.
[INFO] org.apache.maven.plugins: checking for updates from central
[more output]

After all the necessary files are downloaded, you will be shown a list of supported archetypes and will be prompted to select the one that you want to generate.

[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: internal -> appfuse-basic-jsf (AppFuse archetype for creating a web application with Hibernate, Spring and JSF)
2: internal -> appfuse-basic-spring (AppFuse archetype for creating a web application with Hibernate, Spring and Spring MVC)
3: internal -> appfuse-basic-struts (AppFuse archetype for creating a web application with Hibernate, Spring and Struts 2)
[more options]
42: internal -> cocoon-22-archetype-block-plain ([http://cocoon.apache.org/2.2/maven-plugins/])
43: internal -> cocoon-22-archetype-block ([http://cocoon.apache.org/2.2/maven-plugins/])
44: internal -> cocoon-22-archetype-webapp ([http://cocoon.apache.org/2.2/maven-plugins/])
Choose a number: (1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19/20/21/22/23/24/25/26/27/28/29/30/31/32/33/34/35/36/37/38/39/40/41/42/43/44) 15: :

Enter the appropriate number to select the archetype that you want to generate; for example, enter 18 to create a basic Java Web Application project. Next you will be prompted to enter values for groupId(say ‘hello’), artifactId(say ‘HelloWorld’), version(you can accept the default and just press the ENTER key) and package(say ‘war’). You will then be asked for confirmation; type Y and press the ENTER key. For more information on what the above fields mean, read about Maven Co-ordinates.

To learn more about Maven’s archetype plugin, read Maven 2 Archetype plugin usage page.

You can run the basic Java web application project created above in Tomcat web server by running the following command.

# mvn tomcat:run
[lot of output]
[INFO] Starting tomcat server
[INFO] Starting Servlet Engine: Apache Tomcat/5.5.15
[INFO] XML validation disabled
[INFO] Initializing Coyote HTTP/1.1 on http-8080
[INFO] Starting Coyote HTTP/1.1 on http-8080

(If this is the first time you are running the above command, it downloads a lot of necessary files and stores them in the local Maven repository. This is a one-time operation.) You can now access the web application from a location like “http://localhost:8080/HelloWorld/”. ‘HelloWorld’ is the artifactId that we used when creating the sample application. You can read more about running and deploying applications from Maven to Tomcat web server on Maven Tomcat plugin page.

If Jetty web server is installed on your computer, you can also run your web application in Jetty by running the following command:

# mvn jetty:run

How easy it is to switch the container when you are developing Java web applications with the Maven build tool! You can read more about running and deploying applications from Maven to Jetty web server on Maven 2 Jetty Plugin page.


If you want to receive future posts by email, enter your email address here:

Related Posts:

  • Installing Sun Java SE 6, Apache Maven 2 and Tomcat 5.5 on Ubuntu GNU/Linux
  • Installing Sun Java SE 6, Maven 2 and Tomcat 5.5 on Fedora GNU/Linux
  • Installing Sun Java SE 6, Apache Maven 2 and Tomcat 5.5 on Windows OS
  • “Hello, World” Web Application using Struts 2 in IntelliJ IDEA 8.0 M1
  • Java on Gentoo
  • “Hello, World” Web Application using Spring MVC in NetBeans IDE 6.7
  • Is C++ really a bigger language than Java?


  • January 11, 2009

    “Hello, World” Web Application in Ruby on Rails using console

    Filed under: Ruby/Rails — tabrez @ 6:19 pm

    Installation and setup instructions of Ruby on Rails web framework on different operating systems is covered in the following posts:

    1. Setting Up Rails Development Environment on Windows Vista/XP
    2. Setting Up Rails Development Environment on Ubuntu GNU/Linux
    3. Setting Up Rails Development Environment on Fedora GNU/Linux

    If you would rather use an IDE to develop Ruby on Rails applications, Aptana IDE is covered in "“Hello, World” Web Application in Ruby on Rails using Aptana Studio."

    This post describes how to create a basic "Hello, World" web application in Rails using only console tools and a text editor. The instructions work pretty much the same for all operating systems with little to no modifications.

    Make sure that you have the latest versions of all components installed:

    # ruby -v && gem -v && rails -v
    ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-linux]
    1.3.1
    Rails 2.2.2

    (Output text might be slightly different on Windows OS but the version numbers should be the same.)

    To create a new rails project, run the following command which generates the required directory structure for a rails application:

    # rails hello
    # cd hello
    # ls
    app db lib public README test vendor
    config doc log Rakefile script tmp

    The purpose of each directory generated is more or less self-explanatory, like the test directory is for storing test files and the log directory contains various log files.

    Rails application the scaffold generator way

    Scaffolding allows us to generate template code necessary to directly run our application and play with it without having to write a single line of code. We can also open the generated files to take a peek at the generated code. We can then modify this code to our liking or just throw it away and write everything manually once we are satisfied with the prototype. The scaffolding code can be generated, say for a resource called 'person', by running the following command:

    # ruby script/generate scaffold person name:string password:string email:string age:integer

    This command generates(among other files) a Rails migration file in db/xxx_create_people.rb which is responsible to create the database schema for our application; a model in app/models/person.rb; a controller in app/controllers/people_controller.rb and related view files in app/views/people directory. ('people' is used wherever plural of 'person' is needed.) Have a look at the code generated in the migration file:

    RUBY:
    1. create_table :people do |t|
    2.       t.string :name
    3.       t.string :password
    4.       t.string :email
    5.       t.integer :age
    6.  
    7.       t.timestamps
    8.     end

    Run the following commands to initialize the database:

    # rake db:create:all
    # rake db:migrate

    Now we are ready to run the application and use it. Start the WEBrick web server:

    # ruby script/server

    Open your favourite web browser and go to http://localhost:3000/persons url. You should see a page similar to the following screenshot(after I added couple of entries using the "New Person" link):

    Also make sure you look at the code generated in the controller file and the various view files!
    Read the official Getting Started with Rails guide.
    Read more Rails articles on this blog.


    If you want to receive future posts by email, enter your email address here:

    Related Posts:

  • “Hello, World” Web Application in Ruby on Rails using Aptana Studio
  • Setting Up Rails Development Environment on Fedora GNU/Linux
  • Setting Up Rails Development Environment on Ubuntu GNU/Linux
  • Setting Up Rails Development Environment using Aptana Studio
  • Setting Up Rails Development Environment on Windows Vista/XP
  • Setting Up Ruby on Rails Projects with Git and Github
  • Setting Up Development Environment For Grails on Windows Vista/XP



  • Copyright (c) 2006, 2007 Tabrez Iqbal.
    Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved. A copy of the license is included in the section entitled "GNU Free Documentation License".


    Powered by WordPress
    This website is hosted by Dreamhost