Saturday, March 21, 2020

Create Liferay OSGi Module with BLADE CLI


Liferay Provided BLADE CLI tool to create Liferay OSGi modules. BLADE CLI provided many commands and one of the commands is create command. Liferay 7/DXP is providing many OSGi module templates and it will create project skeleton with required configuration files.

As a Developer we simply focus on actual development instead of project configurations. BLADE is also provided way to create modules with two build types Gradle and Maven.

Prerequisite

Install BLADE CLI


BLADE CREATE

The following is BLADE create command with minimum required options.


blade create -t <project-template> -p <package> -c <component-class-name> -v <liferay-version> -b <build-tool> <project-name>


Example Command to create Liferay MVC Portlet OSGi Module

Gradle


blade create -t mvc-portlet -p com.liferaysavvy.sample -c LiferaySamplePortlet -v 7.2 -b gradle sample-gradle-mvc-portlet


Default build type is gradle. You can ignore -b when you are targeting build type is Gradle.

Maven


blade create -t mvc-portlet -p com.liferaysavvy.sample -c LiferaySamplePortlet -v 7.2 -b maven sample-maven-mvc-portlet


Locate to your workspace directory and try above create commands it will create maven and gradle 
Liferay MVC Portlet module.



Maven Liferay Module Project


Gradle Liferay Module Project



Project template list

Use following command to find all available project templates

blade create -l





template list


activator                      
api                              
content-targeting-report         
content-targeting-tracking-action 
control-menu-entry                
form-field                       
fragment                        
freemarker-portlet              
layout-template                  
modules-ext                       
mvc-portlet                        
npm-angular-portlet             
npm-react-portlet               
npm-vuejs-portlet                 
panel-app                         
portlet-configuration-icon      
portlet-provider                 
portlet-toolbar-contributor       
rest
service                      
service-builder               
service-wrapper              
simulation-panel-entry          
social-bookmark                
spring-mvc-portlet              
template-context-contributor      
theme                            
theme-contributor                 
war-core-ext                  
war-hook                          
war-mvc-portlet  


Author

JAXB-API has not been found on module path exception in Liferay 7/DXP

We may encounter following JAXB-API error while working with Liferay OSGi JAX-RS rest modules. Build and deployment might be success but when we are trying to access the REST end-points we may see it in server console logs or in browser as well.

Example:


Error:


JAXBException occurred : Implementation of JAXB-API has not been found on module path or classpath.. com.sun.xml.internal.bind.v2.ContextFactory cannot be found by org.apache.aries.jax.rs.whiteboard_1.0.4


Solution:

Add following JVM argument to the server CATALINA_OPTS in setenv.bat or setenv.sh file based on Operating System.


-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory


setenv.bat



How to add New JVM arguments to Liferay Portal Server, follow the below blog post.

Author

Add new JVM arguments to Liferay Portal Tomcat Server


Sometimes we may need to add new JVM arguments to Liferay Portal Tomcat server.

We have different ways to add JVM arguments to server and here are the options.
Tomcat provided setenv.bat and setenv.sh files in bin directory and we will add new JVM arguments in these files under “CATALINA_OPTS” variable.

JVM Argument syntax


-D[ARGUMENT_NAME]=[ARGUMENT_VALUE]


Windows Operating System

In Windows Operating system, we have to use setenv.bat file to add new JVM arguments
Open setenv.bat file in editor and add your JVM argument as follows and save the file


set "CATALINA_OPTS=%CATALINA_OPTS% -Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory"


Make sure we have to keep the %CATALINA_OPTS% always which means that we are adding new JVM arguments along with existing arguments.
You can also create your custom options and finally append to “CATALINA_OPTS”

Example:


set "LIFERAY_OPTS=-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory"

set "CATALINA_OPTS=%CATALINA_OPTS% %LIFERAY_OPTS%"



Unix/Linux Family Operating Systems

Open setenv.sh file in editor and add your JVM argument as follows and save the file


CATALINA_OPTS="$CATALINA_OPTS -Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory "


Make sure we have to keep the $CATALINA_OPTS always which means that we are adding new JVM arguments along with existing arguments.

You can also create your custom options and finally append to “CATALINA_OPTS”

Example:


LIFERAY_OPTS="-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory"

CATALINA_OPTS="$CATALINA_OPTS $ LIFERAY_OPTS"



Liferay Portal already have many existing CATALINA_OPTS and we have to add new JVM argument to existing list.

setenv.bat

Example setenv.bat file in Liferay Portal Tomcat (tomcat-9.0.17\bin)


set "CATALINA_OPTS=%CATALINA_OPTS% -Dfile.encoding=UTF8 -Djava.locale.providers=JRE,COMPAT,CLDR -Djava.net.preferIPv4Stack=true -Duser.timezone=GMT -Xms2560m -Xmx2560m -XX:MaxNewSize=1536m -XX:MaxMetaspaceSize=512m -XX:MetaspaceSize=512m -XX:NewSize=1536m -XX:SurvivorRatio=7"
set "CATALINA_OPTS=%CATALINA_OPTS% -Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory"


setenv.sh


CATALINA_OPTS="$CATALINA_OPTS -Dfile.encoding=UTF8 -Djava.locale.providers=JRE,COMPAT,CLDR -Djava.net.preferIPv4Stack=true -Duser.timezone=GMT -Xms2560m -Xmx2560m -XX:MaxNewSize=1536m -XX:MaxMetaspaceSize=512m -XX:MetaspaceSize=512m -XX:NewSize=1536m -XX:SurvivorRatio=7"
CATALINA_OPTS="$CATALINA_OPTS -Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory"


Restart servers then new configuration applies to the server.

Liferay IDE/Liferay Developer Studio

If you are using Liferay IDE/Liferay Developer Studio then use server configuration to add new JVM arguments.

Servers View --> Double Click on Liferay Server --> Open Launch Configuration --> Click Arguments --> Edit VM arguments Input

Its editable text area and we can add new variable as follows and Make sure each argument separated by SPACE.


Restart server then new configuration applies to the server.

IntelliJ Idea

If you are using IntelliJ Idea Liferay Plugin Developer Studio then use server configuration to add new JVM arguments

Liferay Server Edit Configuration


Add new JVM arguments in VM Options list as follows and click on OK then configuration will be saved. Make sure each argument separated by SPACE.

Example


-Djavax.xml.bind.JAXBContextFactory=com.sun.xml.bind.v2.ContextFactory



Restart server then new configuration applies to the server.

Author

Recent Posts

Recent Posts Widget

Popular Posts