Quick Start - Maven

Assuming that you have created your Naked Objects application from an archetype then you can use the following commands to build and then run the prototype:-

$ mvn package
$ cd commandline/target/myapp-commandline-1.0-SNAPSHOT-commandline.dir/myapp-commandline-1.0-SNAPSHOT/
$ ./nakedobjects.sh -t exploration

Running a Naked Objects application as a prototype

A Naked Objects application is commonly developed in two stages. First it is developed as standalone prototype, running on a single machine, with no security, and with all the objects in memory. Then it is converted into a deployable application i.e. running on a server with multiple clients, with a persistence layer (most commonly in the form of the Hibernate Object Store) and with full authentication and authorization. (Note that these two phases do not have to be sequential, you might prefer to develop your system feature-by-feature right through to a deployable version.) In this section we show you how to run Naked Objects as prototype; in the next section we show you how to deploy the same domain object model as the real application.

Running a Naked Objects application generally requires some configuration files and images. Resources are typically loaded from the working directory, while specific resources can be loaded from the class path. Assuming that we will be running from the development directory the following structure is typical of a Naked Objects application.

project/
    src/
    xat/
    config/
        nakedobjects.properties
        passwords
    images/
    build.xml
    :

Configuration

Naked Objects loads in one or more properties files during startup. The properties files must contain at least a list of services that the application uses and commonly there is also a list of fixtures that are to be run at startup. In addition to the core properties there may be also other properties that are used by other components. The file nakedobjects.properties is always loaded up, while other properties files relating to specific components are only loaded up if the component they relate to is to be is used. For example when using the DND viewer the system will also load in the file viewer_dnd.properties, and when using the hibernate object store the file persistor_hibernate.properties is loaded. While nakedobjects.properies must exist for the framework to start up properly, all other properties files are optional.

The example nakedobjects.properties file below shows a number of service classes being listed along with a generic repository for accessing Location objects. The prefix is prepended to each class name before loading. The second set of properties lists the fixture classes to load and instantiate.

nakedobjects.services.prefix=org.nakedobjects.example.ecs
nakedobjects.services=repository#Location,resources.CustomerRepository, \
  CustomerFactory, BookingFactory, resources.PaymentMethodFactory, \
  resources.PhoneNumberFactory, LocationFactory

nakedobjects.fixtures.prefix=org.nakedobjects.example.ecs.fixtures
nakedobjects.fixtures=CitiesFixture, BookingsFixture, ContextFixture

Authentication

By default the authentication mechanism is a username/password challenge with the details stored in a password file called passwords. This file is a simple list of user names and their corresponding passwords separated by a colon. The file below shows two users with badly chosen passwords.

jbrown:pass
tsmith:pass

Images

The drag and drop and web interfaces both display icons as part of the views for each object. Images for these icons, and for other uses, are sought in the images directory. The web interface currently only works with GIF images, while the DnD interface will work with GIF, PNG and JPEG images. The following shows images for the main objects in the ECS example.

images
    Booking.gif
    City.gif
    CreditCard.gif
    Customer.gif
    Location.gif
    Telephone.gif

Bootloader

Running a naked objects application is done via the Naked Objects boot loader, which is the class NakedObjects. Without any arguments Naked Objects will be started in prototype mode with the Drag and Drop viewer. The example below shows the Ant target (from the build template file) that will start up Naked Objects in exploration mode. The classpath is simply a list of all the library jars (as compiled by the path element) and the classes compiled by the compile target show previously.

<property name="bootclass" value="org.nakedobjects.runtime.NakedObjects"/>

<path id="libs.external">
  <fileset dir="${lib.dir}">
      <include name="**/*.jar" />
  </fileset>
</path>

<target name="exploration-dnd" depends="compile" 
  description="Run exploration class using drag-and-drop graphical viewer">

    <java fork="yes" classname="${bootclass}">
      <classpath path="${classes.dir}" />
      <classpath refid="libs.external" />
      <arg line="--type exploration --viewer dnd"/>
    </java>
</target>

Run

$ ant exploration-dnd
Buildfile: build.xml

By changing the command line parameters you can change the way that Naked Objects starts up. This can include using different: viewers, such as web browser, command line and drag and drop; persistors, such as Hibernate, XML, and in-memory; and modes, such as standalone, client and server. Details on all the options are listed in the reference section.

TODO: need to discuss the alternative org.nakedobjects.webserver.WebServer bootloader that can be used to run the webapp defined by the webapp project's web.xml descriptor.