WebLab 1.2.5/Developer Guide

From WebLab Wiki
Jump to navigationJump to search

Getting Started

This part explains how to build the WebLab Core from its sources and install it. Note that the WebLab makes extensive use of Maven.

The WebLab compiled artifacts are already available on the OW2 maven repository, see Download. If you do not want to bother with compilation and installation, go to Add OW2 Repository

Getting the sources

First, download the last WebLab sources. The Download sources page provides several methods to retrieve sources.

Building the artifacts

To build the WebLab artifacts, extract all source files and execute the following command:

mvn install

This command will compile, test and install in your local repository:

  • the Weblab model
  • the Weblab extended
  • the Weblab annotator
  • all Weblab Helpers

Adding OW2 maven repository

Instead of building WebLab from source, you can add the maven repository containing WebLab artifacts. To use WebLab artifact in your project, add the following repository in your maven settings:

   <repository>
      <id>OW2 maven repository</id>
      <url>http://maven.ow2.org/maven2</url>
   </repository>
   <repository>
      <id>WebLab Maven repository</id>
      <url>http://maven.weblab-project.org/</url>
   </repository>

Using WebLab as a Maven dependency

To use the WebLab as a dependency in you project, add the corresponding artifact in the pom.xml file of your project.

An example of a simple pom.xml project using the WebLab as a dependency:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>my.group.id</groupId>
  <artifactId>example</artifactId>
  <version>1.0-SNAPSHOT</version>

  <name>My project name</name>

  <description>This project defines the WebLab annotator as a dependency library.</description>


  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.0.2</version>
        <inherited>true</inherited>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
          <encoding>UTF-8</encoding>
          <showWarnings>true</showWarnings>
          <showDeprecations>true</showDeprecations>
          <debug>true</debug>
          <optimize>false</optimize>
          <verbose>true</verbose>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.ow2.weblab.core</groupId>
      <artifactId>annotator</artifactId>
      <version>1.2.7</version>
    </dependency>
  </dependencies>

</project>

The Maven compiler plugin is needed since the WebLab libraries are compiled for a 1.7 version of the Java Runtime Environment.

The Annotator dependency depends on WebLab model and extended artifact. Thus, by defining this dependency, you will also import the WebLab Model and Extended.

Using WebLab in a WebService

To generate a web-service, the simplest way is to add the WebLab service pom parent in the pom.xml file of your project.

An example of a pom.xml WebLab webservice project using the WebLab service parent:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>org.ow2.weblab.webservices</groupId>
		<artifactId>parent</artifactId>
		<version>1.2.6</version>
		<relativePath>../parent/pom.xml</relativePath>
	</parent>

	<groupId>your.group.id</groupId>
	<artifactId>web-service-project</artifactId>
	<version>1.0</version>

	<packaging>war</packaging>

	<name>A Web service</name>
	<description>
		A WebService using WebLab model
	</description>

	<dependencies>
		<!-- set your dependencies here, WebLab model/extended artifacts are directly set as dependencies from the pom parent -->
	</dependencies>

</project>

Using WebLab in a Portlet

To generate a portlet using WebLab model, the simplest way is to add the weblab portlet pom parent in the pom.xml file of your project.

An example of a pom.xml portlet project using the WebLab portlet parent:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>org.ow2.weblab.portlets</groupId>
		<artifactId>parent</artifactId>
		<version>1.2.6</version>
		<relativePath>../parent/pom.xml</relativePath>
	</parent>

	<groupId>your.group.id</groupId>
	<artifactId>portlet-project</artifactId>
	<version>1.0</version>

	<packaging>war</packaging>

	<name>A portlet</name>
	<description>
		A Portlet using WebLab model
	</description>

	<dependencies>
		<!-- set your dependencies here, WebLab model/extended artifacts are directly set as dependencies from the pom parent -->
	</dependencies>

</project>

How to deal with WebLab resources

See WebLab resources factories guide.

How to read/write rdf statements in WebLab Resources

There are two common ways:

  • if you are well versed in RDF, you may use RDF Helpers to read and write your own properties.
  • if you want to read/write well known properties (Dublin Core "language" property or RDFS "label" property for example), you may use Annotators.

Source Examples

The project WebLab Samples contains examples on how to use WebLab API.

Processing Chain creation

See WebLab processing chain creation using POJO.