Mastering Liferay Workspaces and Tooling

Course Overview

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

  1. Open a terminal window and go to the workspace’s root folder.
  2. Run the following command:

    blade help
    
    This returns a complete list of available commands within the workspace, along with a short description.
  3. 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.

  1. Open a terminal window and go to the workspace’s root folder.
  2. Run this command:

    blade create -l
    
    This lists all available templates. Take some time to review the options.
  3. Run this command to generate a Java widget code project:

    blade create -t mvc-portlet -p com.example.portlet my-example-web
    When generating widgets, it’s best to suffix the module name with web so its easier to identify.
  4. Verify the my-example-web folder appears in the workspace’s modules folder.
  5. Navigate to the widget’s folder:

    cd modules/my-example-web
    
  6. List the contents of the folder:

    For Mac/Linux:

    ls -all
    

    For Windows:

    dir
    This folder includes everything you need to get started building a custom Java widget.
  7. Return to workspace’s root folder.
  8. Run this command to generate a theme code project:
    blade create -t theme my-example-theme
    
  9. Verify the my-example-theme folder appears in the workspace’s modules folder.Although Blade generates theme project in the modules folder, it’s best practice to move it to the workspace’s themes folder.
  10. Navigate to the theme’s folder:

    cd modules/my-example-theme
    
  11. List the contents of the folder. It includes everything you need to get started building a custom theme.
  12. Return to workspace’s root folder.
  13. Run this command to generate a ReactJS widget code project:

    blade create -t npm-react-portlet my-example-react-web
    
  14. Verify the my-example-react-web folder appears in the workspace’s modules folder.
  15. Navigate to the widget’s folder:

    cd modules/my-example-react-web
    
  16. 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.

  1. Open a terminal window and go to the workspace’s root folder.
  2. Run this command to start the Liferay server:

    blade server start
    
  3. Navigate to the Java widget’s folder:

    cd modules/my-example-web
    
  4. Run this command to view all available Gradle tasks:

    blade gw tasks
    
  5. Run this command to perform a build:

    blade gw build
    
  6. Run this command to perform a clean:

    blade gw clean
    
  7. 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. 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.

  1. Open a terminal window and go to the workspace’s root folder.
  2. Navigate to the Java widget’s folder:

    cd modules/my-example-web
    
  3. Run this command:

    blade watch
    
    Now Blade monitors this module for changes to its source.
  4. In your file explorer, go to this folder: modules/my-example-web/src/main/resources/META-INF/resources and open the view.jsp file.
  5. Replace its contents with the following code and save your changes.

    <%@ include file="/init.jsp" %>
    We should see this message with BLADE watch!
    
  6. 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.

Loading Knowledge

Capabilities

Product

Education

Contact Us

Connect

Powered by Liferay
© 2024 Liferay Inc. All Rights Reserved • Privacy Policy