Welcome to Reference Implementation, the new Content Delivery web application! This tutorial will take you through creating a custom application from scratch. We assume you are familiar with TypeScript, JavaScript (ES6), Webpack, HTML, XML, React, LESS, CSS, Java, Spring, DXA and Maven.
Some learning material:
- JavaScript (ES6)
- TypeScript Getting Started
- TypeScript Tutorial
- React Fundamentals
- React Hello World
- LESS
- Webpack
- Webpack Course
- Serving Web Content with Spring MVC
- Maven Getting Started Guide
- Getting started with DXA 1.7
- Developing on DXA Java
Make sure you have installed:
- Node.js
- 64 bit version is recommended
- Install NodeJs v6.x or higher
- Maven 3
- Tomcat 8.5
- An IDE which has support for TypeScript / LESS
- An IDE which has support for Java
- IntelliJ IDEA
- ...
- A Content Delivery environment with data
In the following guide we're using IntelliJ IDEA Ultimate (for Java) and Visual Studio Code (for LESS / TypeScript / JavaScript).
You can find the result of this guide here
In order to download some snaphot artifacts which are used by the archetype. We will need to add a reference to the sonatype snaphots repository.
- Open up your main
settings.xml
file. On an Windows machine this file is located atC:\Users\<username>\.m2\settings.xml
, on a Linux Ubuntu it is at/usr/share/maven/conf/settings.xml
. - Add an extra profile inside the
profiles
section (see code snippet below) - Make this the active profile (see code snippet below)
<settings>
<profiles>
<profile>
<id>sonatype-nexus-snapshots</id>
<repositories>
<repository>
<id>sonatype-nexus-snapshots</id>
<name>sonatype-nexus-snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>sonatype-nexus-snapshots</activeProfile>
</activeProfiles>
</settings>
First step you will need to do is to create a new directory.
We've created the following directory on our machine: D:\github\dd-webapp-custom-examples
.
We'll be usign this directory further on in the examples.
Ok Let's start by opening the command prompt and run:
cd "D:\github\dd-webapp-custom-examples"
mvn archetype:generate "-DarchetypeArtifactId=dd-webapp-archetype" "-DarchetypeGroupId=com.sdl.delivery.ish" "-DarchetypeVersion=1.2.0"
Notice that we are using version 1.2.0
, this is just an example. We advise you to use the latest available version.
We'll pick org.company
as our group ID and custom-webapp
as the name of our artifact ID.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] >>> maven-archetype-plugin:3.0.1:generate (default-cli) > generate-sources @ standalone-pom >>>
[INFO]
[INFO] <<< maven-archetype-plugin:3.0.1:generate (default-cli) < generate-sources @ standalone-pom <<<
[INFO]
[INFO] --- maven-archetype-plugin:3.0.1:generate (default-cli) @ standalone-pom ---
[INFO] Generating project in Interactive mode
[INFO] Archetype repository not defined. Using the one from [com.sdl.delivery.ish:dd-webapp-archetype:1.2.0] found in catalog remote
Define value for property 'groupId': org.company
Define value for property 'artifactId': custom-webapp
Define value for property 'version' 1.0-SNAPSHOT: :
Define value for property 'package' org.company: :
Confirm properties configuration:
groupId: org.company
artifactId: custom-webapp
version: 1.0-SNAPSHOT
package: org.company
Y: : y
To buid the project, run the following command from the command line:
cd "D:\github\dd-webapp-custom-examples\custom-webapp"
mvn clean install
Next step, we set up IntelliJ IDEA for development:
- Launch IntelliJ
- Open the directory where you've created the archetype, in our case this is the
D:\github\dd-webapp-custom-examples\custom-webapp
directory
First step is to add the necessary configuration inside the cd_client_config.xml
file, located at src/main/resources/cd_client_conf.xml
. We need to provide the location of the discovery service, the client ID and the client secret of the Content Delivery system we are using.
We'll describe this for usage with the IntelliJ Ultimate Edition and the IntelliJ Community Edition (free). You can find a comparison of both versions here.
After this you are ready to start customizing the application.
There is no tight integration with Tomcat and IntelliJ Community Edition, therefore some manual actions are required.
Install Tomcat plugin:
- Download Tomcat runner plugin for IntelliJ
- Extract zip file inside plugins directory of IntelliJ installation (eg
C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2017.1.2\plugins
) - Restart IntelliJ
Start debugging:
- Start IntelliJ as an Administrator
- Select the
Run
item in the top menu - Open
Edit Configurations
- Select the
+
icon on the top left - Select
Tomcat Runner
- Define a name for the configuration, we're using
Tomcat
- Set path to Tomcat Location
- Add a context, we'll be using
/web-app
as path andD:\github\dd-webapp-custom-examples\custom-webapp\target\custom-webapp-1.0-SNAPSHOT
as the Document Base. - Add a new Maven goal
- Fill in
clean install
inside the command line field
- Close the dialog by clicking the Ok button
- Start the custom web application by selecting
Run
->Debug 'Tomcat'
If you have the paid version of IntelliJ there is already a Tomcat integration.
In order to debug it we'll setup a configuration for Tomcat.
- Select the
Run
item in the top menu - Open
Edit Configurations
- Select the
+
icon on the top left - Go to
Tomcat Server
and selectLocal
- Define a name for the configuration, we're using
Tomcat
- Remove all task from the list at the bottom of the dialog
- Add a new Maven goal
- Fill in
clean install
inside the command line field
-
Select Ok
-
Open the
deployment
tab -
Select the
+
icon next to theDeploy at server startup
list
- Select the exploded war file
- Close the dialog by selecting the Ok button
- Start the custom web application by selecting
Run
->Debug 'Tomcat'