« Back

Creating service builder mvc portlet in Liferay 7 with Liferay IDE 3.

Company Blogs April 26, 2016 By Neil Jin

Liferay IDE Download Page: https://web.liferay.com/downloads/liferay-projects/liferay-ide

Liferay IDE 3 has massive change regarding to Liferay 7.0(Liferay DXP). One of the change is it streamlines the creation of OSGi module portlet by utilizing Liferay Blade tool, gradle elipse plugin and bnd tool.

One of the most concerned question by the Liferay developers is how we develop Service Builder with MVC portlet in new Liferay 7 development pattern.

With Liferay IDE 3 it's quite easy!

First we need to create a Liferay Space project.

A Liferay Workspace is a project container for Liferay porjects, within the Liferay workspace, we can develop and manage Liferay plugins.

And next we need to create a new Module Project by clicking File -> New -> Liferay Module Project, and choose the Project Template Name servicebuilder.

In the Liferay Workspace perspective 

We can see there are 2 gradle project under the service builder project. API project containse the service definition and interfaces, as the service path folder in 6.2. Service project contains the actual implementation of the service, as the service code in src folder in 6.2.

It contains a default service.xml. You can change the xml according to your need. After that, you can run buildservice task of service-builder-project-service in Gradle Task Window. 

After running buildService then run build task, the service will be ready to use.

 

How can we reference this service module in a mvc portlet module?

We use gradle to manage dependency.

We can create a mvc portlet Liferay Module Project. And modify build.gradle file. In our case we can add the following code to the dependency declaration.

compile project(":modules:service-builder-project:service-builder-project-api")

The service will be available to the mvc portlet. If the editor still complain about the dependency you can right click to the project -> gradle -> refreash gradle project to refreash the project.

When you deploy the project, remember to deploy 3 jars for api, service and mvc portlet.

 

You can download an example project here.

Threaded Replies Author Date
[...] Hello folks . i tried to build the... Anonymous June 21, 2016 10:23 PM
I haven't encounter null pointer error. Make... Neil Jin June 21, 2016 11:34 PM
I have updated the blog with an example... Neil Jin June 21, 2016 11:41 PM
Hi Neil, I am facing one issue while build the... Pallavi Havale June 23, 2016 4:50 AM
I have the same message, but it doesn't... Neil Jin June 23, 2016 5:07 PM
Thanks Neil !! One more issue i m facing that,... Pallavi Havale June 24, 2016 5:01 AM
This is maybe because you gradle version is not... Neil Jin July 8, 2016 4:19 AM
Hi Neil, I have created liferay 7 Service... Triveni B September 15, 2016 4:44 AM
Is module1 is your mvc portlet module? Neil Jin September 16, 2016 2:13 AM
Yes Neil, module1 is my portlet. Thanks for... Triveni B September 16, 2016 4:15 AM
Hi Neil, I am using Liferay 7 GA1. I tried to... Harish Kumar July 27, 2016 11:54 PM
If this error appears during build, You can run... Neil Jin July 28, 2016 12:21 AM
Thanks for prompt response Neil. It worked !! Harish Kumar July 28, 2016 12:28 AM
Hi Neil, Thanks for this blog it... hemraj sharma November 10, 2016 7:29 AM
Hi Neil, Thanks for this blog it... hemraj sharma November 10, 2016 7:29 AM
1, make sure the compiled jar has beed deployed... Neil Jin November 13, 2016 7:35 AM
Hi Neil,' Thanks, It worked. Thanks a lot. hemraj sharma November 15, 2016 3:28 AM
Hi Neil, Thanks for your replies. I... hemraj sharma November 15, 2016 4:29 AM
Hi Neil, Thanks for your replies. I... hemraj sharma November 15, 2016 4:29 AM
Yea, this is a known issue. even me, I use to... Neil Jin December 8, 2016 1:08 AM
Hi Neil, Thanks for the post. I created a... Clint Wilde November 15, 2016 3:24 PM
Sorry, just saw your reply. Please if you used... Neil Jin December 8, 2016 1:07 AM
Hi I am getting this error ... Ankit Arora February 3, 2017 3:57 AM
it looks like you don't have internet... Neil Jin February 5, 2017 5:34 PM
Hi Neil thanks for your posts. Is there any way... karthik reddy April 11, 2017 3:31 AM
Hi Karthik, basically, you want to manage jars... Neil Jin April 11, 2017 6:23 AM
Hi Neil, Yes I want to manage jars rather... karthik reddy April 26, 2017 4:41 AM
Please check this blog:... Neil Jin April 26, 2017 6:55 AM
I has run into the same problem. But when I... Joye Luo February 16, 2017 9:17 PM
Hi Joye, Yes, I use Liferay workspace. Neil Jin April 11, 2017 6:20 AM
Thanks Neil. This blog really help me a lot. Joye Luo February 16, 2017 9:19 PM

[...] Hello folks . i tried to build the service and try to add the following code in my MVCPortlet . with this link Refrence but it is not working. Showing the error in popup in eclipse Could not... [...] Read More
Posted on 6/21/16 10:23 PM.
I haven't encounter null pointer error. Make sure you have dependency in build.gradle and you have refreashed the gradle project.
Posted on 6/21/16 11:34 PM in reply to .
I have updated the blog with an example attachment in the bottom.
Posted on 6/21/16 11:41 PM in reply to .
Hi Neil,
I am facing one issue while build the services that,

:SB-service:buildServicePOM relocation to an other version number is not fully supported in Gradle : xml-apis#xml-apis;2.0.2 relocated to xml-apis#xml-apis;1.0.b2.

Please update your dependency to directly use the correct version 'xml-apis#xml-apis;1.0.b2'.

Thanks In advance !!!
Posted on 6/23/16 4:50 AM in reply to Neil Jin.
I have the same message, but it doesn't interrupt the build service process. It will repoint the dependenty to xml-apis#xml-apis;1.0.b2.
Posted on 6/23/16 5:07 PM in reply to Pallavi Havale.
Thanks Neil !!
One more issue i m facing that,
I make connection with mysql .After connection ,I am adding the data into the table but it showing me error in popup window
is :
Unable to build output
Could not execute build using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.13-bin.zip'

Thanks in Advance !!!
Posted on 6/24/16 5:01 AM in reply to Neil Jin.
This is maybe because you gradle version is not correct. Sorry Pallavi, just travel back and got some time to reply.
Posted on 7/8/16 4:19 AM in reply to Pallavi Havale.
Hi Neil,

I am using Liferay 7 GA1. I tried to create service builder project as mentioned and using the default service.xml. buildService task succeed but build task failing with following exception. I tried with other service.xml but getting the same error.

Exception in thread "main" com.liferay.source.formatter.SourceMismatchException
at com.liferay.source.formatter.BaseSourceProcessor.processFormattedFile(BaseSource­Processor.java:2488)
at com.liferay.source.formatter.BaseSourceProcessor.format(BaseSourceProcessor.java­:1024)
at com.liferay.source.formatter.BaseSourceProcessor$1.call(BaseSourceProcessor.java­:106)
at com.liferay.source.formatter.BaseSourceProcessor$1.call(BaseSourceProcessor.java­:101)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
­at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
­at java.lang.Thread.run(Thread.java:745)
:modules:service-builder-project:service-bu­ilder-project-service:checkSourceFormatting FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':modules:service-builder-project:service-builder-project-service:checkSourceFor­matting'.
> Process 'command 'C:\Program Files\Java\jdk1.8.0_51\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Thanks.
Posted on 7/27/16 11:54 PM.
If this error appears during build, You can run deploy task instead of build to by pass source formatter.
Posted on 7/28/16 12:21 AM in reply to Harish Kumar.
Thanks for prompt response Neil. It worked !!
Posted on 7/28/16 12:28 AM in reply to Neil Jin.
Hi Neil,
I have created liferay 7 Service builder and MVC portlets and have followed your steps for adding service dependencies in portlet and refreshed gradle module.
Now there is no compile time erros and able to import all service classes in my mvc portlet
I deployed <modulename>-api,<modulename>-service, and mvc portlets in tomcat server
when i checked logs , mvc portlet status is installed and getting below error.

org.osgi.framework.BundleException: Could not resolve module: module1 [592]
Unresolved requirement: Import-Package: com.bookservice.model.impl

I dont know why dependencies not resolved at run time, please help me
Posted on 9/15/16 4:44 AM in reply to Neil Jin.
Is module1 is your mvc portlet module?
Posted on 9/16/16 2:13 AM in reply to triveni bandaru.
Yes Neil, module1 is my portlet. Thanks for your response
I got the solution from below link
https://web.liferay.com/community/forums/-/message_boards/view_message/79177­774#_19_message_79179381
Posted on 9/16/16 4:15 AM in reply to Neil Jin.
Hi Neil,
Thanks for this blog it provide a great help.
But I was facing the same issue as Harish Kumar was facing. I tried by executing the deploy command instead the build. Command executed successfully.
But when I checked DB there were no tables created.
Please suggest where I have to do changes. I am using
1) Liferay 7.0 with community edition
2) mysql version-14.14 Distrib 5.6.30
3)IDE -3.0.1-ga2-linux32
Thanks a lot.
Posted on 11/10/16 7:29 AM.
Hi Neil,
Thanks for this blog it provide a great help.
But I was facing the same issue as Harish Kumar was facing. I tried by executing the deploy command instead the build. Command executed successfully.
But when I checked DB there were no tables created.
Please suggest where I have to do changes. I am using
1) Liferay 7.0 with community edition
2) mysql version-14.14 Distrib 5.6.30
3)IDE -3.0.1-ga2-linux32
Thanks a lot.
Posted on 11/10/16 7:29 AM.
1, make sure the compiled jar has beed deployed into Liferay
2, make sure the module has been activated
3, makre sure there's no error during running
4, check the db table(s), if not exists, try using control panel -> sys admin to regenerate the table(s).
Posted on 11/13/16 7:35 AM in reply to hemraj sharma.
Hi Neil,'
Thanks, It worked.
Thanks a lot.
Posted on 11/15/16 3:28 AM in reply to Neil Jin.
Hi Neil,
Thanks for your replies.
I came across an issue that if i add an entity in a service builder, or modify an existing Entity in that service builder, The corresponding classes are being created but the Tables in DB are not reflected with the changes(NO new table, and no new field in the table if added.). To achieve the changes I need to do the three steps which were discussed here "https://issues.liferay.com/browse/LPS-67688" under "Only during the development phase". Please suggest any other way if possible, in which I don't need to delete the already created tables in that namespace
Posted on 11/15/16 4:29 AM.
Hi Neil,
Thanks for your replies.
I came across an issue that if i add an entity in a service builder, or modify an existing Entity in that service builder, The corresponding classes are being created but the Tables in DB are not reflected with the changes(NO new table, and no new field in the table if added.). To achieve the changes I need to do the three steps which were discussed here "https://issues.liferay.com/browse/LPS-67688" under "Only during the development phase". Please suggest any other way if possible, in which I don't need to delete the already created tables in that namespace
Posted on 11/15/16 4:29 AM.
Hi Neil,

Thanks for the post.

I created a service builder project, (using the command line entirely), then created an MVC Portlet using the command line. I deployed the 2 jars just fine, but when I add the dependency to my portlet's build.gradle file, and build within Eclipse, I get errors:

Project with path ':modules:tasks:tasks-api' could not be found in root project 'TaskPortlet'.

My project structure is this:
ParentDir
+TaskPortlet
+tasks
+tasks-api
+tasks-service

So what do I need to change so my TasksPortlet can see my service jars?

Thanks much.
Posted on 11/15/16 3:24 PM.
Sorry, just saw your reply.
Please if you used the correct method compile project(":modules:tasks:tasks-api") in your TaskPortlet

Second, please make your tasks-api and tasks-serverce are sub projects of tasks project

hope it helps
Posted on 12/8/16 1:07 AM in reply to Clint Wilde.
Yea, this is a known issue. even me, I use to remove tables which is not convenient.
Posted on 12/8/16 1:08 AM in reply to hemraj sharma.
Hi I am getting this error

:modules:tasks:tasks-service:buildService FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':modules:tasks:tasks-service:buildService'.
> Could not resolve all dependencies for configuration ':modules:tasks:tasks-service:serviceBuilder'.
> Could not resolve com.liferay:com.liferay.portal.tools.service.builder:1.0.133.
Required by:
com.liferay.docs.tasks:tasks-service:1.0.0
> Could not resolve com.liferay:com.liferay.portal.tools.service.builder:1.0.133.
> Could not get resource 'https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public/com/life­ray/com.liferay.portal.tools.service.builder/1.0.133/com.liferay.portal.tools.se­rvice.builder-1.0.133.pom'.
> Could not GET 'https://cdn.lfrs.sl/repository.liferay.com/nexus/content/groups/public/com/life­ray/com.liferay.portal.tools.service.builder/1.0.133/com.liferay.portal.tools.se­rvice.builder-1.0.133.pom'.
> sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED
Total time: 1.068 secs

What is it related to. Can Anybody please help me.
Posted on 2/3/17 3:57 AM.
it looks like you don't have internet connection for IDE.
Posted on 2/5/17 5:34 PM in reply to Ankit Arora.
I has run into the same problem. But when I change to use Liferay workspace instead of creating those projects stand-alone, it works. So do u use Liferay workspace?
Posted on 2/16/17 9:17 PM in reply to Ankit Arora.
Thanks Neil. This blog really help me a lot.
Posted on 2/16/17 9:19 PM.
Hi Neil thanks for your posts. Is there any way to download jars externally to create a liferay plugin project or module in liferay DXP.

Thanks & Regards
Karthik
Posted on 4/11/17 3:31 AM in reply to Neil Jin.
Hi Joye, Yes, I use Liferay workspace.
Posted on 4/11/17 6:20 AM in reply to Joye Luo.
Hi Karthik, basically, you want to manage jars manually rather than using gradle to download the dependencies. Am I correct?
Posted on 4/11/17 6:23 AM in reply to karthik reddy.
Hi Neil,
Yes I want to manage jars rather than connecting to internet when using eclipse IDE. I am able to download the required jars. Is there any way to configure manually to communicating with Gradle?

Thanks & Regards
karthik
Posted on 4/26/17 4:41 AM in reply to Neil Jin.
Please check this blog: https://web.liferay.com/web/user.26526/blog/-/blogs/osgi-module-dependencies
Posted on 4/26/17 6:55 AM in reply to karthik reddy.