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. -
Run this command:
This returns the command’s options so you can learn how to fine tune its behavior.
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. -
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. - Verify the
my-example-web
folder appears in the workspace’smodules
folder. -
Navigate to the widget’s folder:
-
List the contents of the folder:
For Mac/Linux:
For Windows:
This folder includes everything you need to get started building a custom Java widget. - Return to workspace’s root folder.
- Run this command to generate a theme code project:
- 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:
- 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:
- Verify the
my-example-react-web
folder appears in the workspace’smodules
folder. -
Navigate to the widget’s folder:
- 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:
-
Navigate to the Java widget’s folder:
-
Run this command to view all available Gradle tasks:
-
Run this command to perform a build:
-
Run this command to perform a clean:
-
Run this command to perform a clean, build, and deploy all at once:
You’ve successfully built and deployed a Java widget project to your local Liferay bundle using the blade gw
command. To accelerate this process, you can also automate builds and deployments.
Exercise: Automating Builds and Deployments
The blade watch
command is a powerful Blade feature that enables developers to automatically deploy changes to a running Liferay server in real-time. It monitors your source files and redeploys updated modules, eliminating the need to manually restart the server.
- Open a terminal window and go to the workspace’s root folder.
-
Navigate to the Java widget’s folder:
-
Run this command:
Now Blade monitors this module for changes to its source. - In your file explorer, go to this folder:
modules/my-example-web/src/main/resources/META-INF/resources
and open theview.jsp
file. -
Replace its contents with the following code and save your changes.
- In the terminal window where you ran
blade watch
, verify a new build and deployment running automatically.
You've successfully used the blade watch
command to automatically deploy code changes, which can further accelerate development processes.
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