Facade
This tutorial will guide you through the creation of Java facade and JavaScript API for the Eclipse Dirigible Custom Stack.
Prerequisites
This tutorial is assuming, that you've successfully completed the following tutorials:
Steps
-
Create Facade Module:
- Navigate to the root folder of the custom stack (e.g.
<my-custom-stack-path>/custom-stack
). - Navigate to the
modules
folder. - Creatae
facade
folder and navigate to it. - Create
pom.xml
,GreetingsFacade.java
andgreetings.js
files.
- Create new
modules/facade/pom.xml
file. - Paste the following content:
<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>io.dirigible.custom.stack</groupId> <artifactId>custom-stack-modules-parent</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <name>Custom Stack - Modules - Facade</name> <artifactId>custom-stack-modules-facade</artifactId> <packaging>jar</packaging> </project>
- Create
src/main/java/io/dirigible/custom/platform/facade/
folder stucture and navigate to it. - Create new
modules/facade/src/main/java/io/dirigible/custom/platform/facade/GreetingsFacade.java
file. - Paste the following content:
package io.dirigible.custom.platform.facade; public class GreetingsFacade { public static String getGreeting() { return "Welcome to Eclipse Dirigible!"; } }
- Create
src/main/resources/META-INF/dirigible/custom-stack/
folder stucture and navigate to it. - Create new
modules/facade/src/main/resources/META-INF/dirigible/custom-stack/greetings.js
file. - Paste the following content:
exports.getMessage = function() { let username = org.eclipse.dirigible.api.v3.security.UserFacade.getName(); let greeting = Packages.io.dirigible.custom.platform.facade.GreetingsFacade.getGreeting(); return `Hello '${username}'! ${greeting}`; };
Access to Packages
Java classes are accessed by Fully Qualified Name (FQN). For classes that are not packaged in
java
,com
ororg
packages, thePackages
object should be used. - Navigate to the root folder of the custom stack (e.g.
-
Add Modules Dependency:
- Navigate to the
modules
folder. - Open the
pom.xml
file. - Make the following changes:
- Navigate to the
<modules>
section. -
Add the following module:
<modules> <module>all</module> <module>branding</module> <module>facade</module> </modules>
<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>io.dirigible.custom.stack</groupId> <artifactId>custom-stack-parent</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <name>Custom Stack - Modules - Parent</name> <artifactId>custom-stack-modules-parent</artifactId> <packaging>pom</packaging> <modules> <module>all</module> <module>branding</module> <module>facade</module> </modules> </project>
- Navigate to the
all
folder. - Open the
pom.xml
file. - Make the following changes:
- Navigate to the
<dependencies>
section. -
Add the following dependency:
<dependency> <groupId>io.dirigible.custom.stack</groupId> <artifactId>custom-stack-modules-facade</artifactId> <version>1.0.0-SNAPSHOT</version> </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> <parent> <groupId>io.dirigible.custom.stack</groupId> <artifactId>custom-stack-modules-parent</artifactId> <version>1.0.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <name>Custom Stack - Modules - All</name> <artifactId>custom-stack-modules-all</artifactId> <packaging>jar</packaging> <dependencies> <dependency> <groupId>io.dirigible.custom.stack</groupId> <artifactId>custom-stack-modules-branding</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> <dependency> <groupId>io.dirigible.custom.stack</groupId> <artifactId>custom-stack-modules-facade</artifactId> <version>1.0.0-SNAPSHOT</version> </dependency> </dependencies> </project>
- Navigate to the
-
Build the Custom Platform.
- Navigate to the root folder of the project (e.g.
<my-custom-stack-path>/custom-stack
). -
Open the Terminal and execute the following command to build the Custom Platform:
mvn clean install
- Navigate to the root folder of the project (e.g.
-
Run the Custom Platform.
- Navigate to the
releng/target
folder. -
Open the Terminal and execute the following command to run the Custom Platform:
java -jar custom-stack-spring-boot-*.jar
Debugging
To run in debug mode, execute the following command:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 -jar custom-stack-spring-boot-*.jar
-
Go to http://localhost:8080 to access the Custom Stack.
- Navigate to the
-
Test the changes.
- Create a project named
sample-custom-stack
. - Right click on the
sample-custom-stack
project and select New → JavaScript CJS Service. - Enter
greeting.js
for the name of the JavaScript Service. -
Replace the content with the following code:
var response = require("http/v4/response"); let greetings = require("custom-stack/greetings"); let message = greetings.getMessage(); response.println(message); response.flush(); response.close();
-
Save the changes.
- Open the Preview view to see the result.
- Create a project named