Getting started with Geomajas

Geomajas Developers and Geosparc

1.12.0-SNAPSHOT

Abstract

Documentation for first time users to get started with the Geomajas GIS framework.


Table of Contents

1. Starting a new GWT based Geomajas project
1. Prerequisites / Command line
2. Create your Geomajas project
3. Run your Geomajas project
4. Configure your Geomajas project
5. Getting started with database layers
6. How to continue
2. Using Geomajas in your IDE of choice
1. Eclipse
1.1. Running/debugging with the Google Plug-in for Eclipse (embedded Jetty option)
1.2. Running/debugging with the Google Plug-in for Eclipse
2. IntelliJ IDEA
3. NetBeans
3. About
1. About this project
2. License information
3. Author information

List of Figures

1.1. Choose the correct archetype
1.2. Screenshot when building the Geomajas GWT archetype
2.1. Import project as Maven project
2.2. Eclipse project properties dialog, Google Web Toolkit
2.3. Eclipse project properties dialog, Google Web Application
2.4. Debug configurations dialog
2.5. JettyRunner as main class
2.6. Running Jetty
2.7. Running the GWT application
2.8. Classpath of GWT plug-in (no-server mode)
2.9. Open project using pom
2.10. IDEA GWT run configuration
2.11. run gwt:i18 target
2.12. Project structure for simple GWT project

List of Examples

1.1. Create project using Maven archetype
1.2. Build the project and run it

Chapter 1. Starting a new GWT based Geomajas project

Geomajas uses the Apache Maven project management tool for its build and documentation process. The easiest way to start using Geomajas is by creating a new project using the Maven archetype. This will create a simple working project that you can use as a starting point.

1. Prerequisites / Command line

To create the simple project with the Maven archetype, you need to install Maven on your system. Maven can be downloaded from http://maven.apache.org/. We recommend using the latest stable version (2.2.1 at the time of writing). Installing Maven is quite simple: unzip the distribution file in the directory of your choice and make some environment changes so you can run the executable mvn. More information for your specific OS can be found at the bottom of http://maven.apache.org/download.html.

2. Create your Geomajas project

At this point it is assumed that Maven has been successfully installed. Using Maven, you can now create your Geomajas project, called the Geomajas GWT Application archetype.

  1. Step1: Go to the folder you want to create the Geomajas application in, and execute the following command:

    Example 1.1. Create project using Maven archetype

    mvn archetype:generate -DarchetypeCatalog=http://files.geomajas.org/archetype-catalog.xml

    The above catalog will give you the latest stable release, which is what you normally want. If you need the latest snapshot version, use the following catalog:

    mvn archetype:generate -DarchetypeCatalog=http://files.geomajas.org/latest/archetype-catalog.xml

    Maven will now prompt the user for input.

    Note

    If anything fails with these Maven commands, you need to check the output to check the problem. One typical problem is the need to define a proxy to allow Maven to access external repository websites. See the http://maven.apache.org/guides/mini/guide-proxies.html for details.

  2. Step2: Maven will display the full list of available archetypes. Make sure you select the correct one: geomajas-gwt-archetype. In the image below, the correct number would be 36:

    Figure 1.1. Choose the correct archetype

    Choose the correct archetype

  3. Step3: Next Maven asks for the groupId. Often the package name is used, but any other name will do (e.g. myGroupId).

  4. Step4: Next Maven asks for the artifactId. This represents the name for your application (e.g. myApp).

    Note

    The artifactId cannot contain special characters!

  5. Step5: Next Maven asks for the first version for your application. 1.0-SNAPSHOT is a good first version.

  6. Step6: Next Maven asks for the base package wherein to place Java files. By default this is the same as the groupId. Just hit "enter" to continue with the default or enter another package name (e.g. my.app).

    Figure 1.2. Screenshot when building the Geomajas GWT archetype

    Screenshot when building the Geomajas GWT archetype

Tip

You have now created a Geomajas project! Now you are ready to run it.

3. Run your Geomajas project

  1. Step1: Go to the folder with the artifactId name (myApp in the example above) and execute the following command:

    Example 1.2. Build the project and run it

    mvn install jetty:run

    The "install" target will create a web archive (.war file) for the project in the target directory. This .war file can be dropped into a Java application container such as Tomcat.

    The "jetty:run" target will immediately start a jetty server and start the application in it. Jetty is a Java application container that can run your project without the need to install a separate Java application.

  2. Step2: Open a web browser and access your Geomajas application at http://localhost:8080/.

4. Configure your Geomajas project

Once you have your Geomajas project running, you might want to make some modifications to the Geomajas configuration and customize it. More details about the Geomajas configuration can be found in the developer's guide.

Here you find the most important configuration files used in your Geomajas project:

  • main configuration : src/main/webapp/WEB-INF/applicationContext.xml

  • map configuration : src/main/webapp/WEB-INF/mapMain.xml

  • overview map configuration : src/main/webapp/WEB-INF/mapOverview.xml

  • countries layer configuration : src/main/webapp/WEB-INF/clientLayerCountries.xml and src/main/webapp/WEB-INF/layerCountries.xml

  • OpenStreetMap layer configuration : src/main/webapp/WEB-INF/clientLayerOsm.xml and src/main/webapp/WEB-INF/layerOsm.xml

  • GWT configuration file : src/main/java/Application.gwt.xml

  • web.xml: src/main/webapp/WEB-INF/web.xml

If you have the jetty server running and you make changes to the configuration, press ENTER to reload the application without stopping the server.

5. Getting started with database layers

The Geomajas sample application comes with a predefined layer configuration for PostgreSQL/PostGIS and SQLServer databases (configurations for other supported databases like Oracle and MySQL can be added in a similar way).

To activate the database layer, the following steps should be taken:

  1. Create the sample database. This should be a spatially enabled database with name 'app' and login user 'app' with password 'app'.

  2. Import the layer data in the database. For reference , the data is provided as a shape file in the directory: src/main/resources/context/shapes/road.shp. There are also 2 scripts available for both the PostGIS and SQLServer databases: src/main/webapp/WEB-INF/example/road_postgres.sql and src/main/webapp/WEB-INF/example/road_sqlserver.sql. These can be run from PgAdmin or SQL Server Management Studio respectively.

  3. Uncomment the necessary dependencies in your pom.xml file. Geomajas provides 2 layer plugins that can work with databases: Geotools layer and Hibernate layer plugin. The Geotools layer plugin does not require the creation of a Java mapping, which makes it easier to configure, but it also has no support for complex attributes (many-to-one, one-to-many). The Hibernate layer plugin does require Java mapping objects (have a look at the Road.java class to see how the mapping works) but offers complex attribute support instead. The choice of layer plugin will depend on the needs of your application and whether or not you want to make use of the advanced feature editing capabilities of Geomajas. As an example, for the Geotools layer with a PostGIS database, the following dependencies should be uncommented:

    <!-- uncomment if you want to use geotools with postgis, for another db you will need similar dependencies -->
    <dependency>
      <groupId>org.postgis</groupId>
      <artifactId>postgis-jdbc</artifactId>
    </dependency>
    <dependency>
      <groupId>postgresql</groupId>
      <artifactId>postgresql</artifactId>
    </dependency>
  4. Uncomment the necessary application context entries in your web.xml file. This is necessary to add the roads layer to your Spring context definition. The specific entries to uncomment will again depend on your choice of layer plugin and database. For he Geotools layer with a PostGIS database, the following entries should be uncommented:

    <!-- To use Roads layer stored in PostGIS through GeoTools layer, uncomment the following -->
    WEB-INF/example/geotools/mapMain.xml
    WEB-INF/example/geotools/spring-geotools.xml
    WEB-INF/example/geotools/clientLayerRoads.xml
    <!-- for PostGIS -->
    WEB-INF/example/geotools/postgis/layerRoads.xml
  5. Restart your application. An editable road layer should appear.

6. How to continue

The archetype generates a dependency on the geomajas-dep project to manage the version of the Geomajas dependencies. This project exists for the sole purpose of keeping track of the latest released versions. It is quite likely that a new version of geomajas-dep has been released since the latest release of the archetype. Therefore, we recommend you update this dependency to the latest version. You can check the latest version using this URL: http://repo.geomajas.org/nexus/index.html#nexus-search;quick~geomajas-dep.

References which may be interesting to read:

Chapter 2. Using Geomajas in your IDE of choice

This chapter is aimed at Java developers that whish to import the Geomajas project in their favourite IDE and start programming. The use of an IDE is not really required if you only want to configure layers, styles, etc.

1. Eclipse

The combination of Eclipse, maven and GWT is not quite trivial, especially for advanced multi-module projects like Geomajas. There are 2 approaches possible for integrating eclipse with maven:

It is clear that an IDE integrated solution like m2eclipse offers considerable advantages over manually generating Eclipse project configurations:

  • direct import of maven projects

  • support for maven properties and filtering

  • In-place editing of poms

  • full dependency support

For a functional Geomajas setup, the following Eclipse plug-ins should be installed on a fresh Galileo download (http://www.eclipse.org/downloads/):

  • m2eclipse: update site http://m2eclipse.sonatype.org/sites/m2e

  • m2eclipse extras (especially WTP extension): http://m2eclipse.sonatype.org/sites/m2e-extras

  • checkstyle: update site http://eclipse-cs.sf.net/update/

  • SVN team provider: update site http://download.eclipse.org/releases/helios, choose Collaboration ->Subversive SVN Team Provider (Incubation)

  • Google's GWT Eclipse plug-in: http://dl.google.com/eclipse/plugin/3.6 (Plugin and SDK)

1.1. Running/debugging with the Google Plug-in for Eclipse (embedded Jetty option)

There is a classpath issue with the Google Plug-in for Eclipse (GPE) that prevents us from using it in a reliable way when there are multiple versions of artifacts in the maven dependency tree: http://code.google.com/p/google-web-toolkit/issues/detail?id=5033

On top of that, GPE forces the use of the built-in jetty launcher, which has problems with loading libraries from the maven repository. Recent development by Google points in the direction of better maven support, but a as far as we know a stable solution which does not require explicit user interaction is not available. (see http://googlewebtoolkit.blogspot.com/2010/08/how-to-use-google-plugin-for-eclipse.html).

In view of these problems, the following workaround seems to be the most reliable way of using the GWT plugin for us:

  • Run the GWT plug-in with the no-server option (this can be done straight from the project since GWT 2.1

  • Run an embedded Jetty server to replace the GWT server

The following series of steps have to be performed to achieve a working project.

  • Import the project as a maven project

    Figure 2.1. Import project as Maven project

    Import project as Maven project

  • After the project has been imported and the workspace has been built, you should now manually mark the project as a GWT project in the project properties dialog. Open the Google -> Web Toolkit section and mark the checkbox. If the eclipse GWT version differs from the project version, the "Use specific SDK" checkbox will be enabled:

    Figure 2.2. Eclipse project properties dialog, Google Web Toolkit

    Eclipse project properties dialog, Google Web Toolkit

  • In the Google -> Web Application section, the WAR directory should be changed to the default maven war sources directory (src/main/webapp)

    Figure 2.3. Eclipse project properties dialog, Google Web Application

    Eclipse project properties dialog, Google Web Application


  • Open the debug configurations dialog and create a new Java application:

    Figure 2.4. Debug configurations dialog

    Debug configurations dialog

  • Search for JettyRunner as the main class. JettyRunner is a specially prepared main class that starts up Jetty with the correct parameters (port 8888 and src/main/webapp as webapp directory)

    Figure 2.5. JettyRunner as main class

    JettyRunner as main class

  • Run the new Jetty server configuration (in debug mode):

    Figure 2.6. Running Jetty

    Running Jetty

  • Now, run the GWT plug-in in no-server mode by by right-clicking on the project and selecting Debug As -> Web Application (running on an external server):

    Figure 2.7. Running the GWT application

    Running the GWT application

  • Click ok on the dialog screen

  • You can now add breakpoints and debug your application as if it was a normal Java application.

  • If you have multiple versions of GWT in your project workspace, make sure that the gwt-dev jar is in front of the default classpath (reported GWT issue):

    Figure 2.8. Classpath of GWT plug-in (no-server mode)

    Classpath of GWT plug-in (no-server mode)

1.2. Running/debugging with the Google Plug-in for Eclipse

If you want to run your application directly with GPE, some extra actions are needed to avoid classpath problems. You will have to change your web.xml by adding a special context listener that allows Spring component scanning and circumvents a GeoTools problem with the builtin Jetty classloader:

<listener>
 <listener-class>org.geomajas.servlet.PrepareScanningContextListener</listener-class>
</listener>

This solves most of the classpath problems but does not cure the problem of having multiple artifact versions in the classpath! This is usually only a problem when you have several Geomajas projects opened in your workspace. If this is the case, run the GWT plug-in with an embedded Jetty server as explained in the previous chapter and you should be fine. Note that this should be the first listener in your web.xm files, before the spring listeners.

The following steps are needed to run GPE directly:

  • Follow the configuration steps of the indirect mode, right up to the Jetty part

  • Run the project as a GWT Web application by right-clicking on the project and selecting Run as -> Web Application.

  • For debugging, debug the project as a GWT Web application by right-clicking on the project and selecting Debug as -> Web Application.

2. IntelliJ IDEA

The setup in IntelliJ IDEA is quite straightforward and does not require running a separate Maven command. Just open the project from IDEA by selecting the pom in the root directory.

Figure 2.9. Open project using pom

Open project using pom

IDEA will recognize this as a GWT project and assign the correct facet but as always you will have to make your own run configuration (which is fortunately trivial). You will need version 9.0 or later for the GWT 2.0 support.

Figure 2.10. IDEA GWT run configuration

IDEA GWT run configuration

Before being able to use this configuration, you need to invoke the gwt:i18n Maven target to assure the files which are used for internationalisation are available (otherwise, you will get compilation errors). You can do this from the "Maven projects" tab.

Figure 2.11. run gwt:i18 target

run gwt:i18 target

Some additional settings have to be done in the "project structure" dialog. Apart from specifying the GWT installation directory, there is a specific project setting which has to be done manually, which is setting the target Web facet to "Web". The project structure for the simple GWT project should look as follows:

Figure 2.12. Project structure for simple GWT project

Project structure for simple GWT project

After this, you should be able to run the project. Any changes in the source code will be automatically detected, and debugging is possible.

Note

When creating GWT run configurations, it is recommended to increase the amount of memory given to the process. You can do this by entering a higher -Xmx value in the VM parameters field, for example "-Xmx768m".

3. NetBeans

You can both create the project from the archetype or open directly the Maven project in NetBeans. See http://wiki.netbeans.org/MavenBestPractices for more details.

Chapter 3. About

1. About this project

Geomajas is a free and open source GIS application framework for building rich internet applications. It has sophisticated capabilities for displaying and managing geospatial information. The modular design makes it easily extensible. The stateless client-server architecture guarantees endless scalability. The focus of Geomajas is to provide a platform for server-side integration of geospatial data, allowing multiple users to control and manage the data from within their own browser. In essence, Geomajas provides a set of powerful building blocks, from which the most advanced GIS applications can easily be built. Key features include:

  • Modular architecture

  • Clearly defined API

  • Integrated client-server architecture

  • Built-in security

  • Advanced geometry and attribute editing with validation

  • Custom attribute definitions including object relations

  • Advanced querying capabilities (searching, filters, style, ...)

See http://www.geomajas.org/.

2. License information

Copyright © 2009-2010 Geosparc nv.

Licensed under the GNU Affero General Public License. You may obtain a copy of the License at http://www.gnu.org/licenses/

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU Affero General Public License for more details.

The project also depends on various other open source projects which have their respective licenses.

From the Geomajas source (possibly specific module), the dependencies can be displayed using the "mvn dependency:tree" command.

For the dependencies of the Geomajas back-end, we only allow dependencies which are freely distributable for commercial purposes (this for example excludes GPL and AGPL licensed dependencies).

3. Author information

This framework and documentation was written by the Geomajas Developers. If you have questions, found a bug or have enhancements, please contact us through the user fora at http://www.geomajas.org/.

List of contributors for this manual:

  • Pieter De Graef

  • Jan De Moerloose

  • Joachim Van der Auwera

  • Frank Wynants

  • Frank Maes