2.2. Creating a New Application

Creating a new application is as simple as typing one command. However, there is one thing that you should know. The name of the application folder will always be the base package of the application. For example, if the application base package is com.mycompany.myapp than that’s how the folder that your application will live in should be named. The name of the application, i.e., as it appears in the application url, will be the last portion of this package name. This convention is mandatory only if you use command line tool.

Now, let’s create our first application. Move to a folder where the application folder will be created in, that is, a workspace and type to command:

Example 2.1. Creating a New Application

$ wedge –app wedge.eg.testapp 

You should get the next output:

Welcome to Wedge RAD Enviroment!
To quit enter '\q' command. For help enter 'help' command.

(c) Copyright 2005-2006 http://wedge.sourceforge.net

Application 'wedge.eg.testapp' does not exists! Would you like to create it?
[y/n]:y
  creating a new application on folder d:\temp\webapps/wedge.eg.testapp
  Copying 42 files to D:\temp\webapps\wedge.eg.testapp
  Copied 12 empty directories to 6 empty directories under D:\temp\webapps\wedge.eg.testapp
  Creating D:\temp\webapps\wedge.eg.testapp\web\css\testapp.css
	
	...
	
Application created!

Type 'y' to answer yes and your application will be created right way!

2.2.1. Application Structure

The application you've just created has the structure of usual web application. It consits of a two source forlders, one for application sources and one for tests, a web root directory, named 'web' and a build directory where an archive will be created. Also, you will notice that created all the needed configuration files and some extra files that take part of an usual web application. Other things about what get generated you will find out as you'll get to more specific aspects.

Let's explain in more details what get created in a new application.

A tipical java web application consists of a source folder in which all the java sources will stay. Also there is the web root folder, the folder which will be packed into the war archive on deployment.

Here is the java source folders of a tipical application:

Example 2.2. Wedge Application Java Source Folders

And here is a detailed list of all the java related application items:

  • src - the application sources folder

  • src/application.properties - application general settings such as database connection details

  • src/log4j.xml - Log4j configuration file. It contains configuration of logging for Spring, Hibernate, Wedge and your application.

  • test/src - the application test sources folder. You may want to configure your IDE to compile these sources in a different folder then the application's output.

  • build.xml - the ANT build file ready for building you application.

  • testapp.launch - launch configuration for jetty server. This launch configuration will allow you to easy run/debug your application.

  • wedge-testapp.launch - launch configuration that will run command line tool inside Eclipse. Useful for having the command line and the editor in the same application.

  • wedge-config.xml - a XML catalog for Eclipse WTP plugin. Use coresponding Eclipse Preferences setting for importing this file. This will help you to easily edit XML files such as Spring application context and Hibernate mappings.

  • application.license - your application licence. Every java source generated by wedge will contain this text (must be a legal javadoc comment) in its header.

And here is the rest of the project folder:

Example 2.3. Wedge Application WebRoot

2.2.2. Adding Pages to the Application

RAD enviroment comes with some helpful commands that helps you with some repetitive operations such as creating a page or a component, a spring service or DAO with interfaces and their implementations or adding a class to the application model. All this are as simple as typing a command.

Here is a list of commands available with :

Example 2.4. Wedge Command List

app:build      compiles the java classes
 browser:start  starts the browser on Windows System
 hql            starts the emebedded Hibernate Query Tool
 jetty:restart  restarts jetty embedded server
 jetty:start    starts jetty embedded server
 jetty:stop     stops jetty embedded server
 model:class    generates a class for application's model
 model:comp     generates a component for application's model
 spring:dao     generates a spring dao service
 spring:logic   generates a spring business logic service
 wedge:frame    generates a new wedge frame
 wedge:page     generates a new wedge page
 wedge:part     generates a new wedge part (component)

Now, let's create a page! When the application was first created there was an 'home' page that was also generated. Lets create a new one named 'helloWorld' and see what happens.

wedge> wedge:page helloWorld
  Creating template WEB-INF/pages/helloWorld.html
  Creating class wedge/test/web/pages/HelloWorld.java

  <wedge:page name="helloWorld" class="web.pages.HelloWorld" />

Three things just happend. There was created a java class and its coreponding template and a portion of xml configuration was printed out. This little piece of code its all you have to add to the Spring application configuration file in order to specifiy a page. In the next chapter we will explain why pages, frames and parts (components) are configured in the Spring application context and how you can make use of Spring IOC capabilities.

Naming conventions

By using simple naming conventions you may add pages to your application without declaring them in the application context. If you create a page template in the WEB-INF/pages folder named, say, 'myPage.html' and a class named <application package>.web.page.MyPage then you can reffer to you page in the application by using the identifier myPage.

[Warning] Template Extensions

Currently only the html extension is supported.