Create a Web Application Using the Oracle JET Command-Line Interface
Use the Oracle JET command-line interface (CLI) to create, build, and serve web applications that run in desktop and mobile browsers.
Before you can create your first Oracle JET web application using the CLI, you must also install the prerequisite packages if you haven’t already done so. For details, see Install Oracle JET Tooling.
Topics
Note:
You can also use the tooling to create hybrid mobile applications. For additional information, see Understanding the Hybrid Mobile Application Workflow.Scaffold a Web Application
Use the Oracle JET command-line interface (CLI) to scaffold an application that contains a blank template or one pre-configured Starter Template with a basic layout, navigation bar, or navigation drawer. Each Starter Template is optimized for responsive web or hybrid mobile applications. After scaffolding, you can modify the application as needed.
About ojet create Command Options for Web Applications
Use ojet create
with optional arguments to create the Oracle JET web application and scaffolding.
The following table describes the available ojet create
command options and provides examples for their use.
Option | Description |
---|---|
|
Application location. If not specified, the application is created in the current directory. The directory will be created during scaffolding if it doesn’t already exist. |
|
Template to use for the application. Specify one of the following:
|
|
Displays a man page for the |
About Scaffolding a Web Application
Scaffolding is the process you use in the Oracle JET command-line interface (CLI) to create an application that contains a blank template or one pre-configured with a basic layout, navigation bar, or navigation drawer. Each pre-configured template is optimized for responsive web or hybrid mobile applications. After scaffolding, you can modify the application as needed.
The following image shows the differences between the pre-configured Starter Templates. The blank template contains an index.html
file but no UI features. The basic:web
template is similar to the blank template but adds responsive styling that will adjust the display when the screen size changes. The navbar:web
and navdrawer:web
templates contain sample content and follow best practices for layout, navigation, and styling that you can also modify as needed.
Note:
Do not confuse the basic template which contains no content with the Oracle JET QuickStart Basic application available in NetBeans 8.2 examples. The NetBeans application uses thenavdrawer:web
layout shown above and contains the same sample content.
If you want your web application to look more like a mobile application, you can scaffold your web application with a hybrid mobile version of the basic, navbar, or navdrawer template: basic:hybrid
, navbar:hybrid
, or navdrawer:hybrid
.
After scaffolding, you can perform the following tasks to customize your application:
About the Web Application File Structure
The Oracle JET scaffolding process creates files and folders that you modify as needed for your application.
The new application will have a directory structure similar to the one shown in the following image.
The application folders contain the application and configuration files that you will modify as needed for your own application.
Directory or File | Description |
---|---|
|
Contains the Node.js modules used by the tooling. |
|
Contains the Also contains template hook scripts that you can modify to define new build and serve steps for your application. See Customize the Web Application Tooling Workflow |
|
Site root for your application. Contains the application files that you can modify as needed for your own application and should be committed to source control. The content will vary, depending upon your choice of template. Each template, even the blank one, will contain an Other templates may contain view templates and viewModel scripts pre-populated with content. For example, if you specified the navbar template during creation, the |
|
Defines rules for application folders to ignore when using a GIT repository to check in application source. Users who do not use a GIT repository can use |
|
Contains the default source and staging file paths that you can modify if you need to change your application's file structure. |
|
Defines npm dependencies and project metadata. |
After scaffolding, you can perform the following tasks to customize your application:
Modify the Web Application’s File Structure
You can modify your scaffolded application’s file structure if the default structure doesn’t meet your needs.
The oraclejetconfig.json
file in your application’s top level directory contains the default source and staging file paths that you can modify.
{
"paths": {
"source": {
"common": "src",
"web": "src-web",
"hybrid": "src-hybrid",
"javascript": "js",
"styles": "css",
"themes": "themes"
},
"staging": {
"web": "web",
"hybrid": "hybrid",
"themes": "themes"
}
},
"generatorVersion": "7.0.0"
}
To change the web application’s file structure:
Add Hybrid Mobile Features to Web Applications
Add Cordova hybrid mobile platforms to your web application using the ojet add hybrid
command. When you run this command, the tooling creates a Cordova project and new hybrid-src
and web-src
directories, enabling you to create both web and hybrid mobile applications from the same source.
Since mobile applications typically provide a very different user experience to web applications, taking this approach typically works best if your web application has been designed to suit a mobile device user experience.
Before you begin:
- If needed, install the mobile tooling packages, as described in Understanding the Hybrid Mobile Application Workflow.
- Familiarize yourself with the folder structure of your web application. The file locations will vary in this procedure if you modified your directory structure, as described in Modify the Web Application’s File Structure or Modify the Hybrid Mobile Application’s File Structure.
- Familiarize yourself with the
ojet create --hybrid
command optionsplatforms
,appid
,appname
, andhelp
. The command to add hybrid mobile features to your web application uses the same option values as theojet create --hybrid
command, as described in Scaffold a Hybrid Mobile Application.
To add hybrid mobile platforms to your web application:
Build a Web Application
Use the Oracle JET command-line interface (CLI) to build a development version of your web application before serving it to a browser. This step is optional.
Change to the application’s root directory and use the ojet build
command to build your application.
ojet build [--theme=themename[:android|ios|web|windows] --themes=theme1,theme2,...
--sass]
Tip:
You can enterojet help
at a terminal prompt to get help for specific Oracle JET CLI options.
Done.
The command will also create a web folder in your application’s root to contain the built content.
Note:
You can also use theojet build
command with the --release
option to build a release-ready version of your application. For information, see Package and Deploy Web Applications.
About ojet build Command Options for Web Applications
Use the ojet build
command with optional arguments to build a development version of your web application before serving it to a browser.
The following table describes the available options and provides examples for their use.
Option | Description |
---|---|
|
Theme to use for the application. The theme defaults to You can also enter a different |
|
Themes to include in the application, separated by commas. If you don’t specify the |
|
Manages Sass compilation. If you add Sass and specify the If you add Sass and do not specify a theme option, Sass compilation will not occur by default, and you must specify |
Customize the Web Application’s Build Steps
Edit oraclejet-build.js
to modify default build behavior. For example, you can add additional libraries to your application or change the default markers used to inject links into the application’s index.html
during build time.
The Oracle JET tooling defines default build and serve behavior in node_modules/@oracle/oraclejet-tooling/lib/defaultconfig.js
. The first part of the file contains the default build configuration, including entries for application paths and other options used during the build process. To modify defaults or add your own, edit oraclejet-build.js
and remove comments from the options that you want to configure. The file contains detailed instructions for each configurable option.
Oracle JET will merge the options with the default configuration during the build. However, be aware that fileList
options will completely replace the corresponding option in the default configuration and will not be merged.
Before you begin:
- Familiarize yourself with the
ojet build
command optionstheme
,themes
, andsass
, as described in Build a Web Application.
Serve a Web Application
Use ojet serve
to run your web application in a local web server for testing and debugging. By default, the Oracle JET live reload option is enabled which lets you make changes to your application code that are immediately reflected in the browser.
Before you begin:
- Familiarize yourself with the
ojet serve
command optiontheme
when you want to run the application with an optional platform and a custom theme, as described in Customize Themes Using the Tooling. - Optionally, use the
ojet serve
command with the--release
option to serve a release-ready version of your application, as described in Package and Deploy Web Applications.
About ojet serve Command Options for Web Applications
Use ojet serve
to run your web application in a local web server for testing and debugging.
The following table describes the available ojet serve
options and provides examples for their use.
Option | Description |
---|---|
|
Server port number. If not specified, defaults to 8000. |
|
Live reload port number. If not specified, defaults to 35729. |
|
Enable the live reload feature. Live reload is enabled by default ( Use Disabling live reload can be helpful if you’re working in NetBeans or other IDE and want to use that IDE’s mechanism for loading updated applications. |
|
Manages Sass compilation. If you add Sass and specify the If you add Sass and do not specify a theme option, Sass compilation will not occur by default, and you must specify |
|
Build the app before you serve it. By default, an app is built before you serve it ( Use |
|
Theme to use for the application. The theme defaults to |
|
Themes to use for the application, separated by commas. If you don’t specify the |
|
Serves the application, as if to a browser, but does not launch a browser. Use this option in cloud-based development environments so that you can attach your browser to the app served by the development machine. |
Customize the Web Application’s Serve Steps
Edit oraclejet-serve.js
to modify default serve behavior. For example, you can specify your own watch tasks or specify actions specific to web or hybrid applications.
The Oracle JET tooling defines default build and serve behavior in node_modules/@oracle/oraclejet-tooling/lib/defaultconfig.js
. The second half of the file contains the default serve configuration, including entries for application paths and other options used during the serve process. To modify defaults or add your own, edit scripts/config/oraclejet-serve.js
and remove comments from the options that you want to configure. The file contains detailed instructions for each configurable option.
Oracle JET will merge the options with the default configuration during the build. However, be aware that rewriting the three default watch targets (sourceFiles
, sass
, and themes
) can result in unpredictable behavior.
To customize serve behavior:
Customize the Web Application Tooling Workflow
Hook points that Oracle JET tooling defines let you customize the behavior of the JET build and serve processes when you want to define new steps to execute during the tooling workflow using script code that you write.
When you create an application, Oracle JET tooling generates script templates in the /scripts/hooks
application subfolder. To customize the Oracle JET tooling workflow you can edit the generated templates with the script code that you want the tooling to execute for specific hook points during the build and serve processes. If you do not create a custom hook point script, Oracle JET tooling ignores the script templates and follows the default workflow for the build and serve processes.
To customize the workflow for the build or serve processes, you edit the generated script template file named for a specific hook point. For example, to trigger a script at the start of the tooling's build process, you would edit the before_build.js
script named for the hook point triggered before the build begins. That hook point is named before_build
.
Therefore, customization of the build and serve processes that you enforce on Oracle JET tooling workflow requires that you know the following details before you can write a customization script.
-
The type of application that you created: either a web application or a hybrid mobile application.
-
The Oracle JET build or serve mode that you want to customize:
-
Debug — The default mode when you build or serve your application, which produces the source code in the built application.
-
Release — The mode when you build the application with the
--release
option, which produces minified and bundled code in a release-ready application.
-
-
The appropriate hook point to trigger the customization.
-
The location of the default hook script template to customize.
About the Build and Serve Hook Points for Web Applications
The Oracle JET hooks system defines various script trigger points, also called hook points, that allow you to customize the build and serve workflow across the various build and serve modes. Customization relies on script files and the script code that you want to trigger for a particular hook point.
The following table identifies the hook points and the workflow customizations they support in the Oracle JET tooling create, restore, build, and serve processes. Unless noted, hook points for the build and serve processes support both debug and release mode.
Hook Point | Supported Tooling Process | Description |
---|---|---|
after_app_create |
create | This hook point triggers the script with the default name after_app_create.js immediately after the tooling concludes the create application process. A script for this hook point can be used with a web application or a hybrid mobile application.
|
after_app_restore |
restore | This hook point triggers the script with the default name after_app_restore.js immediately after the tooling concludes the restore application process. A script for this hook point can be used with a web application or a hybrid mobile application.
|
before_build |
build | This hook point triggers the script with the default name before_build.js immediately before the tooling initiates the build process. A script for this hook point can be used with a web application or a hybrid mobile application.
|
before_release_build |
build (release mode only) | This hook point triggers the script with the default name before_release_build.js before the uglify step and the requirejs bundling step occur. A script for this hook point can be used with a web application or a hybrid mobile application.
|
before_hybrid_build |
build | This hook point triggers the script with the default name before_hybrid_build.js before the cordovaPrepare and CordovaCompile build steps occur. A script for this hook point can be used only with a hybrid mobile application.
|
after_build |
build | This hook point triggers the script with the default name after_build.js immediately after the tooling concludes the build process. A script for this hook point can be used with a web application or a hybrid mobile application.
|
after_component_create |
build | This hook point triggers the script with the default name after_component_create.js immediately after the tooling concludes the create Web Component process. A script for this hook point can be used to modify the build process specifically for a project that defines a Web Component.
|
after_component_build |
build (debug mode only) | This hook point triggers the script with the default name after_component_build.js immediately after the tooling concludes the Web Component build process. A script for this hook point can be used to modify the build process specifically for a project that defines a Web Component.
|
before_serve |
serve | This hook point triggers the script with the default name before_serve.js before the web serve process connects to and watches the application. In the case of hybrid builds, it also precedes the cordovaClean and cordovaServe step. A script for this hook point can be used with a web application or a hybrid mobile application.
|
after_serve |
serve | This hook point triggers the script with the default name after_serve.js after all build process steps complete and the tooling serves the application. A script for this hook point can be used with a web application or a hybrid mobile application.
|
Change the Hooks Subfolder Location
When you create an application, Oracle JET tooling generates script templates in the /scripts/hooks
application subfolder. Your development effort may require you to relocate hook scripts to a common location, for example to support team development.
hooks
subfolder using a generated configuration file that specifies the script paths. When the tooling reaches the hook point, it executes the corresponding script which it locates using the configuration files in the /scripts/config
application subfolders. If you change the default location of the hooks
subfolder, you must edit the following configuration files to specify the new directory path.
-
<myApp_Home>/scripts/config/oraclejet-build.js
- Specifies the location and hook type of build process scripts. -
<myApp_Home>/scripts/config/oraclejet-serve.js
- Specifies the location and hook type of serve process scripts.
If your development effort requires you to relocate hook scripts to a common location, update the path
attributes in the hook system configuration files to specify the new target path for the scripts. When you edit the configuration file, do not change the type
attributes. The hook system relies on the type
attribute to execute the script for a specific build/serve hook point.
Create a Build or Serve Hook Script for Web Applications
You can create a hook point script to define a new build or serve process step for your web application. To create a hook script, you edit the hook script template associated with a specific hook point in the tooling build and serve workflow.
The Oracle JET hooks system defines various script trigger points, also called hook points, that allow you to customize the build and serve workflow across the various build and serve modes. Customization relies on script files and the script code that you want to trigger for a particular hook point. Note that the generated script templates that you modify with your script code are named for their corresponding hook point.
To customize the workflow for the build or serve processes, you edit the generated script template file named for a specific hook point. For example, to trigger a script at the start of the tooling's build process, you would edit the before_build.js
script named for the hook point triggered before the build begins. That hook point is named before_build
.
The following example illustrates a build customization using the after_build
hook. This hook script is an example of adding a customize task after the build finishes.
'use strict’;
const fs = require('fs');
const archiver = require('archiver');
module.exports = function (configObj) {
return new Promise((resolve, reject) => {
console.log("Running after_build hook.");
//Set up the archive
const output = fs.createWriteStream('my-archive.war');
const archive = archiver('zip');
//Callbacks for the archiver
output.on('close', () => {
console.log('Files were successfully archived.');
resolve();
});
archive.on('warning', (error) => {
console.warn(error);
});
archive.on('error', (error) => {
reject(error);
});
//Archive the web folder and close the file
archive.pipe(output);
archive.directory('web', false);
archive.finalize();
});
};
In this example, assume the script templates reside in the default folder generated when you created the application. The goal is to package the application into a ZIP file. Because packaging occurs after the application build process completes, this script is triggered for the after_build
hook point. For this hook point, the modified script template after_build.js
will contain the script code to zip the application, and because the .js
file resides in the default location, no hooks system configuration changes are required.
Tip:
OJET tooling reports when hook points are executed in the message log for the build and serve process. You can examine the log in the console to understand the tooling workflow and determine exactly when the tooling triggers a hook point script.
Pass Arguments to a Build or Serve Hook Script for Web Applications
You can pass extra values to a hook script from the command line interface when you build or serve the web application. The hook script that you create can use these values to perform some workflow action, such as creating an archive file from the contents of the web
folder.
--user-options
flag to the command line interface for Oracle JET to define user input for the hook system when you build or serve the web application. The --user-options
flag can be appended to the build or serve commands and takes as arguments one or more space-separated, string values:ojet build --user-options="some string1" "some string2" "some stringx"
archive-file
set to the archive file name by using the --user-options
flag on the Oracle JET command line.ojet build web --user-options="archive-file=deploy.zip"
If the flag is appended and the appropriate input is passed, the hook script code may write a ZIP file to the /deploy
directory in the root of the project. The following example illustrates this build customization using the after_build
hook. The script code parses the user input for the value of the user defined archive-file
flag with a promise to archive the application after the build finishes by calling the NodeJS function fs.createWriteStream()
. This hook script is an example of taking user input from the command line interface and processing it to achieve a build workflow customization.
'use strict';
const fs = require('fs');
const archiver = require('archiver');
const path = require('path');
module.exports = function (configObj) {
return new Promise((resolve, reject) => {
console.log("Running after_build hook.");
//Check to see if the user set the flag
//In this case we're only expecting one possible user defined
//argument so the parsing can be simple
const options = configObj.userOptions;
if (options){
const userArgs = options.split('=');
if (userArgs.length > 1 && userArgs[0] === 'archive-file'){
const deployRoot = 'deploy';
const outputArchive = path.join(deployRoot,userArgs[1]);
//Ensure the output folder exists
if (!fs.existsSync(deployRoot)) {
fs.mkdirSync(deployRoot);
}
//Set up the archive
const output = fs.createWriteStream(outputArchive);
const archive = archiver('zip');
//callbacks for the archiver
output.on('close', () => {
console.log(`Archive file ${outputArchive} successfully created.`);
resolve();
});
archive.on('error', (error) => {
console.error(`Error creating archive ${outputArchive}`);
reject(error);
});
//Archive the web folder and close the file
archive.pipe(output);
archive.directory('web', false);
archive.finalize();
}
else {
//Unexpected input - fail with information message
reject(`Unexpected flags in user-options: ${options}`);
}
}
else {
//nothing to do
resolve();
}
});
};