Loading Audio...
Creating Code Projects for Clarity
Local Liferay bundles provide an environment for developing and testing code projects, enabling rapid iteration and experimentation. Clarity’s developers want to familiarize themselves with available templates. In these exercises, you’ll create, build, and deploy basic code projects using Blade templates.
Exercise: Learning How to Use Blade Create
The blade help [command]
command provides detailed information about specific commands, including parameters or options you can use to fine tune its behavior. Here you’ll
- Open a terminal window and go to the workspace’s root folder.
-
Run the following command:
This returns a complete list of available commands within the workspace, along with a short description.blade help
-
Run this command:
blade help create
This returns the command’s options so you can learn how to fine tune its behavior.
Usage: create [options] [name] Options: --add-ons Set to true for add on options. Default: false -b, --build, -P, --profile-name Specify the profile to use when invoking the command. -c, --classname If a class is generated in the project, provide the name of the class to be generated. If not provided defaults to project name. -d, --dir The directory where to create the new project. --help Get help on a specific command. --js-framework Specify the javascript framework which will be used in the generated project. (metaljs)|(react) --jsTarget The js project target to use when creating js project. --jsType The js project type to use when creating js project. --liferay-product The option for Liferay Platform product. (portal)|(dxp) Default: portal -p, --package-name The Java package to use when generating Java source. --refresh-releases Force Blade to check for new releases Default: false * -t, --template The project template to use when creating the project. To see the list of templates available use blade create -l|--list-templates -v, --liferay-version The version of Liferay to target when creating the project. Available options are 7.0, 7.1, 7.2, 7.3, 7.4.
All optional, except for the
-t
or--template
command, as indicated by the asterisk.
Now that you’ve reviewed available options, you’ll explore available templates.
Exercise: Creating Code Projects
The blade create
command provides a streamlined way to generate new Liferay code projects, such as modules and themes. It automatically scaffolds the required files and directories for your chosen project type, accelerating your code projects while adhering to Liferay's development standards. Here you'll explore available templates and create three sample projects.
- Open a terminal window and go to the workspace’s root folder.
-
Run this command:
This lists all available templates. Take some time to review the options.blade create -l
-
Run this command to generate a Java widget code project:
When generating widgets, it’s best to suffix the module name with web so its easier to identify.blade create -t mvc-portlet -p com.example.portlet my-example-web
- Verify the
my-example-web
folder appears in the workspace’smodules
folder. -
Navigate to the widget’s folder:
cd modules/my-example-web
-
List the contents of the folder:
For Mac/Linux:
ls -all
For Windows:
This folder includes everything you need to get started building a custom Java widget.dir
- Return to workspace’s root folder.
- Run this command to generate a theme code project:
blade create -t theme my-example-theme
- Verify the
my-example-theme
folder appears in the workspace’smodules
folder.
Although Blade generates theme project in themodules
folder, it’s best practice to move it to the workspace’sthemes
folder. -
Navigate to the theme’s folder:
cd modules/my-example-theme
- List the contents of the folder.
It includes everything you need to get started building a custom theme. - Return to workspace’s root folder.
-
Run this command to generate a ReactJS widget code project:
blade create -t npm-react-portlet my-example-react-web
- Verify the
my-example-react-web
folder appears in the workspace’smodules
folder. -
Navigate to the widget’s folder:
cd modules/my-example-react-web
- List the contents of the folder.
It includes everything you need to get started building a custom ReactJS widget.
Great! You've created three sample code projects, each providing a foundational structure for building custom Liferay modules. While these projects currently contain only boilerplate code, they are ready for deployment and further development.
Exercise: Executing Gradle Wrapper Tasks
The blade gw
command simplifies the execution of Gradle tasks within your Liferay workspace. With it, you can execute Gradle Wrapper tasks by passing the task name as an argument. This is particularly helpful when working in directories several levels deep within your workspace, as it eliminates the need to navigate back to the root directory where the Gradle Wrapper is located. Here you’ll run this command for the Java widget.
- Open a terminal window and go to the workspace’s root folder.
-
Run this command to start the Liferay server:
blade server start
-
Navigate to the Java widget’s folder:
cd modules/my-example-web
-
Run this command to view all available Gradle tasks:
blade gw tasks
-
Run this command to perform a build:
blade gw build
-
Run this command to perform a clean:
blade gw clean
-
Run this command to perform a clean, build, and deploy all at once:
blade gw deploy
You’ve successfully built and deployed a Java widget project to your local Liferay bundle using the blade gw
command.
Conclusion
Great! You've learned how to create, build, and deploy code projects using Blade CLI within your local Liferay bundle. Next, you’ll review what you’ve learned before moving on to the next module.
Capabilities
Product
Education
Contact Us