Introduction

We will show you here how to create a service using a maven archetype provided for the purpose. You will need for that :

  • Java Developing Kit (JDK) in version 1.7 (Sun or OpenJDK)
  • Maven installed with Version greater 3.0.4
  • Eclipse Helios or Greater
  • Some Java and Maven Skills

Creating a New Project

Generating it from Archetype

Select a folder that will receive a project : /home/workspaces/nway_services for example. Then execute this command :

mvn archetype:generate -DarchetypeArtifactId=sp-archetypes-service -DarchetypeRepository=http://sp.nway.org/nexus/content/repositories/releases/ -DarchetypeVersion=5.4.15
  • Respond to all the questions
  • Validate the answer
  • You should see that a new folder has been generated with the same name of your ArchetypeId. Let's say that it is "test-service"
  • Replace 5.4.15 with the willing version.
cd test-service && mvn install
  • Now the project should be compiling and installed into your local repository
  • All the tests should have been executed successfully.
  • All the needed dependencies should have been retrieved from our public repositories.

Note that if you would like to use the last snapshot of the project, use the repository of snapshots and the right version. (5.4.15-SNAPSHOT for example)

Detail of the Package

ClassLoader Process

Class Loader will load all the files from hotload directory into the class loader, then it will identify maven project and finally it will load specific spring files if they exists.

If your service needs external libraries, don't forget to add them.

Assembly and Generated Binary

Assembly is already enabled within the generated archetype. Please execute this command to generate it.

mvn clean package (or install or deploy)

The needed file to move to the hotload directory of the service is at into target/sp-${project.artifactId}-service-5.4.15.zip

Spring Files that are loaded

When the jars are loaded into the class loader, it will search for :

  • config/spring/modules/services/application-context-services-*.xml : Definition of a Service : See the example for more details
  • config/spring/application-context-boot-*.xml : Definition of the Internationalization : See the example for more details.

Eclipse and Developpments

To develop on a IDE (like Eclipse), you just need to import the generated project as an existing Maven Project. Let's have a look at Eclipse's process :

Import Box

Then you should select the generated folder.

Import Box Select Box

Finally, go until the end of the process. You will see your project imported into your Eclipse Workspace.

Developping a Service

To create a service, you can check all the services that are into the distribution package

Here is an example of a empty service. Please place it at the right package directory.

http://sp.nway.org/data/test_service.java.data

Here is the definition of the service. Please place this file at config/spring/modules/services/ respecting this pattern : application-context-service-XXX.xml

http://sp.nway.org/data/test_service.xml.data

Test Files and Deployment

To make the test the example code, please follow these simple instructions :

Deployment

You need to have a server that is ready to run (database configured, ...), then unzip the content of target/sp-${project.artifactId}-service-5.4.15.zip into the following directory of the server : target/server/default/hotload/lib

Data File

Create a file into target/server/default/import/data with this content :

http://sp.nway.org/data/test_data.xml.data

Configuration File

Create a file into target/server/default/import/configuration with this content :

http://sp.nway.org/data/test_configuration.xml.data

Declaration File

Create a file into target/server/default/import/declaration with this content :

http://sp.nway.org/data/test_declaration.xml.data

Launching

After creating the later files at the right place, please restart the engine