Scout/Tutorial/3.8/Maven Tycho Build
Contents
Introduction
This tutorial shows how to build an existing Scout application using Maven Tycho. Therefore we use the Minicrm application as base Scout application to integrate it into the Maven Tycho world.
Installation / Prerequisites
This tutorial assumes that your environment fulfills the following requirements.
Eclipse
Eclipse for Scout Developers Juno
Download-URL: http://www.eclipse.org/downloads/packages/eclipse-scout-developers/junor
m2eclipse
Updatesite-URL: http://download.eclipse.org/releases/juno (or http://download.eclipse.org/technology/m2e/releases)
choose: m2e - Maven Integration for Eclipse (1.1.0.20120530-0009)
Install m2e connectors: Window > Preferences > Maven > Discovery > Open Catalog
choose: Tycho Configurator
Optional: EGit
Updatesite-URL: http://download.eclipse.org/releases/juno (or http://download.eclipse.org/egit/updates)
choose: Eclipse EGit (2.0.0.201206130900-r) Eclipse JGit (2.0.0.201206130900-r)
Maven
Installation guide: http://maven.apache.org/download.html#Installation
Part I - Maven Tycho Integration
- 1. Create new Eclipse Project (used as parent POM)
- 2. Generate POMs for existing projects / plug-ins
mvn org.eclipse.tycho:tycho-pomgenerator-plugin:generate-poms -DgroupId=org.eclipse.minicrm -Dversion=1.0.0-SNAPSHOT -DextraDirs==../org.eclipse.minicrm.client,../org.eclipse.minicrm.server,../org.eclipse.minicrm.shared,../org.eclipse.minicrm.ui.rap,../org.eclipse.minicrm.ui.swing,../org.eclipse.minicrm.ui.swt
Sample pom.xml:
<?xml version="1.0" encoding="UTF-8"?> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.eclipse.scout.autotest</groupId> <artifactId>org.eclipse.scout.autotest</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../org.eclipse.scout.autotest.parent/</relativePath> </parent> <artifactId>org.eclipse.scout.autotest.client</artifactId> <packaging>eclipse-plugin</packaging> </project>
- 3. Convert every project into a Maven Project: Configure > Convert to Maven Project...
- 4. [Optional] Resolve Warnings caused by the previous steps (see Problems-View)
- Delete every bin directory and fix build.properties files (Cause: The project's output folder was changed from /bin to /target/classes)
- Delete duplicate Maven Coordinates (groupId and version)
- 5. Extend parent POM configuration
- Add Eclipse and RAP platform Repositories (using Maven Profiles)
<profiles> <profile> <id>platform-juno</id> <activation> <activeByDefault>true</activeByDefault> <property> <name>platform-version-name</name> <value>juno</value> </property> </activation> <properties> <eclipse.repo.url>http://download.eclipse.org/releases/juno</eclipse.repo.url> <rap.repo.url>http://download.eclipse.org/rt/rap/1.5/runtime</rap.repo.url> <platform.version>[3.8,3.9)</platform.version> <tycho.version>0.15.0</tycho.version> </properties> </profile> </profiles> <repositories> <repository> <id>eclipse platform</id> <url>${eclipse.repo.url}</url> <layout>p2</layout> </repository> <repository> <id>rap platform</id> <url>${rap.repo.url}</url> <layout>p2</layout> </repository> </repositories>
- Replace existing Build settings
<build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-maven-plugin</artifactId> <version>${tycho.version}</version> <extensions>true</extensions> </plugin> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>target-platform-configuration</artifactId> <configuration> <environments> <environment> <os>win32</os> <ws>win32</ws> <arch>x86</arch> </environment> </environments> </configuration> </plugin> </plugins> <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>target-platform-configuration</artifactId> <version>${tycho.version}</version> <configuration> <filters> <!-- work around Equinox bug 348045 --> <filter> <type>p2-installable-unit</type> <id>org.eclipse.equinox.servletbridge.extensionbundle</id> <removeAll /> </filter> </filters> </configuration> </plugin> </plugins> </pluginManagement> </build>
- 6. Build parent POM
mvn clean package
Part II - Build Swing client (building an Eclipse Product)
- 1. Create new Eclipse Project (holding the client Product)
- 2. Add / Create Swing client Product
- Important: Tycho only supports *.product file in the project root
- Important: The *.product file has to contain the attribute 'uid' (correspond to the ID field in the Product Configurator view)
- 3. Create POM configuration
- pom.xml
<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> <parent> <groupId>org.eclipse.minicrm</groupId> <artifactId>org.eclipse.minicrm</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../org.eclipse.minicrm/</relativePath> </parent> <artifactId>org.eclipse.minicrm.swing.product</artifactId> <packaging>eclipse-repository</packaging> <properties> <product.id>org.eclipse.minicrm.swing</product.id> <product.outputDirectory>${project.build.directory}/products/${product.id}/win32/win32/x86</product.outputDirectory> <product.finalName>minicrm</product.finalName> </properties> <build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-director-plugin</artifactId> <executions> <execution> <id>materialize-products</id> <phase>package</phase> <goals> <goal>materialize-products</goal> </goals> </execution> </executions> <configuration> <products> <product> <id>${product.id}</id> </product> </products> </configuration> </plugin> <!-- Workaround: Use an existing config.ini file (caused by the problem that tycho will always generate a default one) --> <plugin> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <resources> <resource> <directory>${project.build.directory}/../</directory> <filtering>false</filtering> <includes> <include>config.ini</include> </includes> </resource> </resources> <outputDirectory>${product.outputDirectory}/configuration</outputDirectory> <overwrite>true</overwrite> </configuration> </execution> </executions> </plugin> <!-- Configure the assembly plugin to build the final client zip file --> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>assembly.xml</descriptor> </descriptors> <finalName>${product.finalName}</finalName> <appendAssemblyId>false</appendAssemblyId> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
- assembly.xml
<assembly> <id>org.eclipse.minicrm.client.zip</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <!-- exported product files --> <fileSet> <directory>${product.outputDirectory}</directory> <outputDirectory>/${product.finalName}</outputDirectory> <excludes> <exclude>p2/**</exclude> <exclude>eclipsec.exe</exclude> <exclude>artifacts.xml</exclude> </excludes> </fileSet> </fileSets> </assembly>
- 4. Convert to a Maven Project: Configure > Convert to Maven Project...
- 5. Update the parent POM
- Extend the modules by the new Maven Module
- Define the newly used Maven Plugins in pluginManagement
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <version>2.5</version> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-director-plugin</artifactId> <version>${tycho.version}</version> </plugin>
- 6. Build parent POM
Part III - Build server (building an Eclipse Product)
- 1. Create new Eclipse Project (holding the server Product)
- 2. Add / Create server Product
- 3. Create POM configuration
- pom.xml
<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> <parent> <groupId>org.eclipse.minicrm</groupId> <artifactId>org.eclipse.minicrm</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../org.eclipse.minicrm/</relativePath> </parent> <artifactId>org.eclipse.minicrm.server.product</artifactId> <packaging>eclipse-repository</packaging> <properties> <product.id>org.eclipse.minicrm.server.product</product.id> <product.outputDirectory>${project.build.directory}/products/${product.id}/win32/win32/x86</product.outputDirectory> <product.finalName>minicrm</product.finalName> </properties> <build> <plugins> <plugin> <groupId>org.eclipse.tycho</groupId> <artifactId>tycho-p2-director-plugin</artifactId> <executions> <execution> <id>materialize-products</id> <phase>package</phase> <goals> <goal>materialize-products</goal> </goals> </execution> </executions> <configuration> <products> <product> <id>${product.id}</id> </product> </products> </configuration> </plugin> <!-- Workaround: Use an existing config.ini file (caused by the problem that tycho will always generate a default one) --> <plugin> <artifactId>maven-resources-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>copy-resources</goal> </goals> <configuration> <resources> <resource> <directory>${project.build.directory}/../</directory> <filtering>false</filtering> <includes> <include>config.ini</include> </includes> </resource> </resources> <outputDirectory>${product.outputDirectory}/configuration</outputDirectory> <overwrite>true</overwrite> </configuration> </execution> </executions> </plugin> <!-- Configure the assembly plugin to build the final server war file --> <plugin> <artifactId>maven-assembly-plugin</artifactId> <configuration> <descriptors> <descriptor>assembly.xml</descriptor> </descriptors> <finalName>${product.finalName}</finalName> <appendAssemblyId>false</appendAssemblyId> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
- assembly.xml
<assembly> <id>org.eclipse.minicrm.server.war</id> <formats> <format>war</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <!-- web-inf template --> <fileSet> <directory>${basedir}/templates/WEB-INF</directory> <outputDirectory>/WEB-INF</outputDirectory> <includes> <include>**</include> </includes> </fileSet> <!-- exported product files --> <fileSet> <directory>${product.outputDirectory}</directory> <outputDirectory>/WEB-INF/eclipse</outputDirectory> <includes> <include>configuration/**</include> <include>plugins/**</include> </includes> </fileSet> </fileSets> </assembly>
- 4. Convert to a Maven Project: Configure > Convert to Maven Project...
- 5. Update the parent POM
- Extend the modules by the new Maven Module
- 6. Add WEB-INF template to match Equinox in a Servlet Container requirements (directory location has to match the referred fileSet in assembly.xml)
- A running WEB-INF template can be extracted from a Scout SDK exported war file. Details can be found here.
- 7. Build parent POM
Part IIII - Advanced stuff
Support Rayo Look and Feel for Eclipse Scout
Add new P2-Repository with the corresponding Update Site URL
Support JDBC Drivers for Eclipse Scout
Add new P2-Repository with the corresponding Update Site URL
Integrate the JRE into the client zip
Extend the assembly.xml's fileSets definition:
<!-- integrate the JRE into the client zip --> <fileSet> <directory>/path/to/jre</directory> <outputDirectory>/${product.finalName}/jre</outputDirectory> </fileSet>