Chapter 15. Building and running the employee rostering starter application
You can build the employee rostering starter application from the source code and run it as a JAR file.
Alternatively, you can use your IDE, for example, Eclipse (including Red Hat CodeReady Studio), to build and run the application.
15.1. Preparing deployment files
You must download and prepare the deployment files before building and deploying the application.
Procedure
-
Download the
rhpam-7.9.1-reference-implementation.zip
file from the Software Downloads page for Red Hat Process Automation Manager 7.9. - Unzip the downloaded archive.
-
Copy the contents of the
jboss-rhba-7.9.1.GA-maven-repository/maven-repository
subdirectory into the~/.m2/repository
directory. Expand the
rhpam-7.9.1-optaweb-employee-rostering.zip
file that is extracted from the reference implementation archive.The
optaweb-employee-rostering-distribution-7.44.0.Final-redhat-00006
folder is created. This folder is the base folder in subsequent parts of this document.NoteFile and folder names might have higher version numbers than specifically noted in this document.
15.2. Running the Employee Rostering starter application JAR file
You can run the Employee Rostering starter application from a JAR file included in the reference implementation download.
Prerequisites
-
You have downloaded and extracted the
rhpam-7.9.1-reference-implementation.zip
file as described in Section 15.1, “Preparing deployment files”. - A Java Development Kit is installed.
- Maven is installed.
- The host has access to the Internet. The build process uses the Internet for downloading Maven packages from external repositories.
Procedure
-
In a command terminal, change to the
sources
directory. Enter the following command:
mvn clean install -DskipTests
- Wait for the build process to complete.
-
Navigate to the
optaweb-employee-rostering-distribution-7.44.0.Final-redhat-00006/sources/optaweb-employee-rostering-standalone/target
directory. Enter the following command to run the Employee Rostering JAR file:
java -jar optaweb-employee-rostering-standalone-*-exec.jar
NoteThis command starts the employee rostering application with a non-production database. To start the employee rostering application with a production database, add the
--spring.profiles.active=production
argument to the preceding command.-
To access the application, enter
http://localhost:8080/
in a web browser.
15.3. Building and running the Employee Rostering starter application using Maven
You can use the command line to build and run the employee rostering starter application.
If you use this procedure, the data is stored in memory and is lost when the server is stopped. To build and run the application with a database server for persistent storage, see Section 15.4, “Building and running the employee rostering starter application with persistent data storage from the command line”.
Prerequisites
- You prepared the deployment files as described in Section 15.1, “Preparing deployment files”.
- A Java Development Kit is installed.
- Maven is installed.
- The host has access to the Internet. The build process uses the Internet for downloading Maven packages from external repositories.
Procedure
-
Navigate to the
optaweb-employee-rostering-backend
directory. Enter the following command:
mvn spring-boot:run
-
Navigate to the
optaweb-employee-rostering-frontend
directory. Enter the following command:
npm start
NoteIf you use
npm
to start the server,npm
monitors code changes.-
To access the application, enter
http://localhost:3000/
in a web browser.
15.4. Building and running the employee rostering starter application with persistent data storage from the command line
If you use the command line to build the employee rostering starter application and run it, you can provide a database server for persistent data storage.
Prerequisites
- You prepared the deployment files as described in Section 15.1, “Preparing deployment files”.
- A Java Development Kit is installed.
- Maven is installed.
- The host has access to the Internet. The build process uses the Internet for downloading Maven packages from external repositories.
- You have a deployed MySQL or PostrgeSQL database server.
Procedure
-
In a command terminal, navigate to the
optaweb-employee-rostering-standalone/target
directory. Enter the following command to run the Employee Rostering JAR file:
java -jar optaweb-employee-rostering-standalone-*-exec.jar --spring.profiles.active=production spring.datasource.url=<DATABASE_URL> --spring.datasource.username=<DATABASE_USER> --spring.datasource.password=<DATABASE_PASSWORD>
In this example, replace the following placeholders:
-
<DATABASE_URL>
: URL to connect to the database, for examplejdbc:postgresql://postgresql:5432/MY_DATABASE
-
<DATABASE_USER>
: The user to connect to the database -
<DATABASE_PASSWORD>
: The password for<DATABASE_USER>
-
15.5. Building and running the employee rostering starter application using IntelliJ IDEA
You can use IntelliJ IDEA to build and run the employee rostering starter application.
Prerequisites
- You have downloaded the Employee Rostering source code, available from the Employee Rostering GitHub page.
- IntelliJ IDEA, Maven, and Node.js are installed.
- The host has access to the Internet. The build process uses the Internet for downloading Maven packages from external repositories.
Procedure
- Start IntelliJ IDEA.
-
From the IntelliJ IDEA main menu, select File
Open. - Select the root directory of the application source and click OK.
-
From the main menu, select Run
Edit Configurations. - In the window that appears, expand Templates and select Maven. The Maven sidebar appears.
-
In the Maven sidebar, select
optaweb-employee-rostering-backend
from the Working Directory menu. -
In Command Line, enter
spring-boot:run
. - To start the back end, click OK .
-
In a command terminal, navigate to the
optaweb-employee-rostering-frontend
directory. Enter the following command to start the front end:
npm start
-
To access the application, enter
http://localhost:3000/
in a web browser.