I am working in a somewhat substantial application, and there is some common logic that I've put in an utils.py (you can tell where this is going).
I am not sure where I should put utils.py, or if I should have more than one copy of it, or if I should install it as a module itself.
Consider this simplified application layout from realpython.com
helloworld/
│
├── helloworld/
│ ├── __init__.py
│ ├── runner.py
│ ├── hello/
│ │ ├── __init__.py
│ │ ├── hello.py
│ │ └── helpers.py
│ │
│ └── world/
│ ├── __init__.py
│ ├── helpers.py
│ └── world.py
│
└── README.md
You have the two main files hello.py and world.py, and there is some hello.py specific helper functions in the adjacent helpers.py.
However, what if there is a substantial amount of logic that is common to both helpers.py; say a sqlalchemy connection or some dataclasses that are endemic across the application.
To make the conversation concrete, suppose I have a dataclass User that is needed pretty much everywhere. Where should I put the file that defines User so that it is available in all the other .py files?
On the one hand I understand the idea behind a directory tree (it's not a tree if the leafs all import utils.py). But what's the alternative? To copy that logic everywhere?
I want to compile my applications with the following tree in yocto project:
myapps/
├── Papps1
│ ├── module-apps1
│ │ └── app1
│ │ ├── include
│ │ │ ├── include files
│ │ ├── configure.ac
│ │ ├── Makefile
│ │ └── other source files
│ └── Papps2
│ └── app2
│ ├── include
│ ├── include files
│ ├── CMakeLists.txt
│ └── other source files
└── recipies_apps
├── recipies_app1.bb
└── recipies_app2.bb
is there any solution to compile this architecture tree in yocto ?
When writing an Xcode extension, any commands you define automatically appear as one long list under Xcode's 'Editor/' menu.
For instance, if you define an extension called 'My First Xcode Extension' with eight commands, it appears like this...
Xcode
├── File Menu
├── Edit Menu
├── View Menu
├── Find Menu
├── Navigate Menu
└── Editor Menu
├── My First Xcode Extension <-- Your extension appears here
│ ├── Command1 <-- All your commands are listed here
│ ├── Command2
│ ├── Command3
│ ├── Command4
│ ├── Command5
│ ├── Command6
│ ├── Command7
│ └── Command8
└── Some Other Extension
├── CommandA
└── CommandB
However, some of the commands are related, so I want to group them, like this...
Xcode
├── File Menu
├── Edit Menu
├── View Menu
├── Find Menu
├── Navigate Menu
└── Editor Menu
├── My First Xcode Extension
│ ├── Command1
│ ├── Command2
│ ├── -------- <-- Need separator here
│ ├── Command3
│ ├── Command4
│ ├── Command5
│ ├── -------- <-- and here
│ ├── Command6
│ ├── Command7
│ └── Command8
└── Some Other Extension
├── CommandA
└── CommandB
Here's an example of what I'm after
class Extension: NSObject, XCSourceEditorExtension {
var commandDefinitions: [[XCSourceEditorCommandDefinitionKey:Any]] {
return [
[XCSourceEditorCommandDefinitionKey.classNameKey : String(reflecting:FirstCommandClass.self),
XCSourceEditorCommandDefinitionKey.identifierKey : "doSomething",
XCSourceEditorCommandDefinitionKey.nameKey : "Do something cool"],
[ // What goes here to create a separator...],
[XCSourceEditorCommandDefinitionKey.classNameKey : String(reflecting:SecondCommandClass.self),
XCSourceEditorCommandDefinitionKey.identifierKey : "doSomethingElse",
XCSourceEditorCommandDefinitionKey.nameKey : "Do something else just as cool"]
]
}
}
Is it possible to add a separator?
That’s not currently supported.
I have two SBT projects as outlined below.
├── Project 1
│ │
│ └── src
│ └── main
│ ├── scala
│ │ └── com
│ │ └── xyz
│ │ └── <*.scala>
│ └── resources
│ └── <Typesafe & Log4J config files>
│
│
└── Project 2
│
├── src
│ └── main
│ ├── scala
│ │ └── com
│ │ └── xyz
│ │ └── <*.scala>
│ └── resources
│ └── <Typesafe & Log4J config files>
│
├── resources
│ └── <JS, HTML, Image files etc.>
├── other-dir-1
│
├── other-dir-2
│
└── other-dir-3
Compiling Project 1 (actually running SBT exportedProducts task) produces the following directory structure. unmanagedResourceDirectories points to Project1/src/main/resources. I believe this is the default resourceDirectory (as mentioned in Customizing Paths). In other words, files in default resource directory are automatically added by exportedProducts
├── Project 1
└── target
└── scala-2.10
└── classes
├── com
│ └── xyz
│ └── <*.class>
└── <Typesafe & Log4J config files>
For Project 2, I want the following directory structure to be produced by exportedProducts.
├── Project 2
└── target
└── scala-2.10
└── classes
├── com
│ └── xyz
│ └── <*.class>
├── <Typesafe & Log4J config files>
│
└── resources
└── <JS, HTML, Image files etc.>
To do this I added the following to SBT build file in the appropriate project definition.
unmanagedResourceDirectories in Compile += baseDirectory.value
excludeFilter in unmanagedResources := HiddenFileFilter || "other-dir-*"
includeFilter in unmanagedResources :=
new SimpleFileFilter(_.getCanonicalPath.startsWith((baseDirectory.value / "resources").getCanonicalPath))
This correctly includes resources directory but doesn't include the files from Project2\src\main\resources. The target directory looks like the
├── Project 2
└── target
└── scala-2.10
└── classes
├── com
│ └── xyz
│ └── <*.class>
└── resources
└── <JS, HTML, Image files etc.>
Adding a custom resource directory in some way masks the content of the default resource directory. I tried something along the lines of what was mentioned in this SO post but wasn't successful.
The other thing that I tried was to set unmanagedResourceDirectories in Compile += baseDirectory.value / "resources" and remove both includeFilter and excludeFilter. This adds the files from Project2\src\main\resources correctly but adds the files & directories from Project2\resources directly to Project2\target\scala-2.10\classes. The target directory looks like the following
├── Project 2
└── target
└── scala-2.10
└── classes
├── com
│ └── xyz
│ └── <*.class>
├── <Typesafe & Log4J config files>
│
└── <JS, HTML, Image files etc.>
I need to make custom queries to the liferay database including JOIN, etc.
My research took me to use the Service Builder strategy.
But when I read about the service builder, you need to define entities in the service.xml file. I do not need an entity, I am willing to use existing entities, for example JournalArcticle, etc.
I would appreciate if someone could direct me to the correct way to go.
The Query I need to use:
SELECT ja.*
FROM liferay.journalarticle ja
INNER JOIN liferay.assetentry ae
ON ja.resourcePrimKey = ae.classPK
INNER JOIN liferay.assetentries_assettags ae_at
ON ae.entryId = ae_at.entryId
INNER JOIN liferay.assettag tags
ON ae_at.tagId = tags.tagId
where tags.name = "actualités de recherche"
;
JournalArticle, assetentries_assettags, AssetTag, AssetEntry are all legacy liferay entities.
I am using liferay 6.1.1-GA2
I read that:
http://www.liferay.com/fr/documentation/liferay-portal/6.1/development/-/ai/define-object-relational-maps-liferay-portal-6-1-dev-guide-en
and that:
http://www.liferay.com/fr/web/sten.martinez/blog/-/blogs/using-a-legacy-db-with-service-builder
Basicaly, I follow the service builder rule and adapt it to maven environment.
Colored version of the post: http://blog.melard.fr/post/123556374437/liferay-implementing-your-custom-service-using
Environnement
------------------------------------
liferay: liferay-portal-6.1.1-ce-ga2
------------------------------------
PAY ATTENTION
If you define a variable hot.deploy.listeners in your portal-ext.properties file, be sur to add the com.liferay.portal.deploy.hot.SpringHotDeployListener class or you might get a BeanLocator is not set error.
I’ve been studying the way to implement a custom service using custom sql based on existing entities.
Case study
I need to retrieve the last version of JournalArticles using pagination adn tag name.
References
blog
Get last version of last journal articles
The answer from that blog entry is to retrieve all the articles and then for each article check if it is the last version of the article using that method:
if(JournalArticleLocalServiceUtil.isLatestVersion(groupId,journalobj.getArticleId(),journalobj.getVersion())){
// here logic will come or you can create another list to add those articles with latest version
}
Determine latest version of Web Content in Liferay
This is another solution, worse than the one mentionned before as it retrieve all the articles and then for each article, check if the articleId has been already loaded.
List articles = JournalArticleLocalServiceUtil.getStructureArticles(GROUPID, STRUCTUREID);
ListIterator it = articles.listIterator();
List checkedArticleIds = new ArrayList();
while (it.hasNext()) {
JournalArticle article = it.next();
if (checkedArticleIds.contains(article.getArticleId())) {
continue; // previous article version already checked
}
JournalArticle articleLastVersion = JournalArticleLocalServiceUtil.getLatestArticle(GROUPID, article.getArticleId());
checkedArticleIds.add(article.getArticleId());
System.out.println("Added articleId " + article.getArticleId() + " with version " + article.getVersion());
}
Find Liferay Latest Journal Atticles By Tag Name
public List getArticlesByTags(long groupId, String tagName)
throws PortalException, SystemException {
AssetEntryQuery assetEntryQuery = new AssetEntryQuery();
long[] anyTagIds = AssetTagLocalServiceUtil.getTagIds(groupId, new String[]{"alllocation", tagName});
assetEntryQuery.setAnyTagIds(anyTagIds);
List assetEntryList = AssetEntryLocalServiceUtil.getEntries(assetEntryQuery);
List journalArticleList = new ArrayList();
for (AssetEntry ae : assetEntryList) {
JournalArticleResource journalArticleResourceObj = JournalArticleResourceLocalServiceUtil
.getJournalArticleResource(ae.getClassPK());
JournalArticle journalArticleObj = JournalArticleLocalServiceUtil.getArticle(groupId,
journalArticleResourceObj.getArticleId());
journalArticleList.add(journalArticleObj);
}
return journalArticleList;
}
The first article entries are not possible because they retrieve all the articles in the database and then process them in order to get the latest versions of each article. It is possible for small entry sets. But when you get to thousands of articles, it will get very slow.
I like better the third article because you only get a limited amount or articles
Implement a custom service using Service Builder
I wanted to use a single method to get last article version by tag name using an SQL Query and let the database handle the joins
SELECT ja.*
FROM JournalArticle as ja
JOIN (
SELECT SUBSTRING_INDEX(GROUP_CONCAT(uuid_ ORDER BY version DESC),',',1) AS uuid_LastVersion
FROM JournalArticle ja
INNER JOIN assetentry ae
ON ja.resourcePrimKey = ae.classPK
INNER JOIN AssetEntries_AssetTags ae_at
ON ae.entryId = ae_at.entryId
INNER JOIN AssetTag tags
ON ae_at.tagId = tags.tagId
where tags.name = ?
GROUP BY articleId
ORDER BY articleId DESC
) as uuids
ON ja.uuid_ = uuids.uuid_LastVersion
After doing a lot of research, I found out that Service Builder was the way to go. I read the manual.
Why all that fuss around ORM, I did not want to create a new table, what I need is to access existing entities, remember? And I am not using Ant, who is using Ant nowadays? I am using Maven. So I had to understand how to create the sevice using maven and then where do I needed to put my classes in order to get my service up and running.
Build a service
In order to build a service, you can use a maven archetype.
mvn archetype:generate
then choose the option: com.liferay.maven.archetypes:liferay-servicebuilder-archetype (Provides an archetype to create Liferay Service Builder portlets.)
The Lifferay version: 2: 6.1.1
Define value for property 'groupId': : com.my.cms
Define value for property 'artifactId': : service
Define value for property 'version': 1.0-SNAPSHOT: :
Define value for property 'package': com.my.cms: :
The archetype then generate some code and modify the pom.xml of the current directory if any
directory:
pom.xml
service
├── pom.xml
├── service-portlet
│ ├── pom.xml
│ └── src
│ └── main
│ ├── resources
│ │ └── portlet.properties
│ └── webapp
│ ├── css
│ │ └── main.css
│ ├── icon.png
│ ├── js
│ │ └── main.js
│ ├── view.jsp
│ └── WEB-INF
│ ├── liferay-display.xml
│ ├── liferay-plugin-package.properties
│ ├── liferay-portlet.xml
│ ├── portlet.xml
│ ├── service.xml
│ └── web.xml
└── service-portlet-service
└── pom.xml The pom.xml on the parent directory is modified to add the “service” module. Be carreful to modify it if you already have a “modules” tag in order to add the “service” module in that tag.
<modules>
<module>service
</modules> As you can see, the Service Builder generated two portlets:
service-portlet
service-portlet-service
The service-portlet is a WAR containing the service to be deployed on you application server.
The service-portlet-service is a JAR containing the classes to be deployed in your portlet on the application server.
Implementation
service.xml
The first thing is to modify the service.xml file in order to have Service Builder to create all the stubs you need to register your service in liferay.
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.1.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_1_0.dtd">
<!-- service/service-portlet/src/main/webapp/WEB-INF/service.xml -->
<service-builder package-path="com.my.cms">
<namespace>service
<entity name="MyService" local-service="true" remote-service="true">
</entity>
</service-builder>
As you can see, I removed all the content of the entity tag, changed the name attribute to “MyService” instead of “Foo” and removed the uuid attribute.
Now, run service builder
cd service
mvn liferay:build-service
[INFO] Reactor Summary:
[INFO]
[INFO] service ........................................... SUCCESS [0.538s]
[INFO] service Portlet Service ........................... SUCCESS [0.299s]
[INFO] service Portlet ................................... SUCCESS [0.322s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
you can see the directory structure as some new files:
├── pom.xml
├── service-portlet
│ ├── pom.xml
│ └── src
│ └── main
│ ├── java
│ │ └── com
│ │ └── my
│ │ └── cms
│ │ └── service
│ │ ├── base
│ │ │ ├── MyServiceLocalServiceBaseImpl.java
│ │ │ ├── MyServiceLocalServiceClpInvoker.java
│ │ │ ├── MyServiceServiceBaseImpl.java
│ │ │ └── MyServiceServiceClpInvoker.java
│ │ ├── http
│ │ │ └── MyServiceServiceSoap.java
│ │ └── impl
│ │ ├── MyServiceLocalServiceImpl.java
│ │ └── MyServiceServiceImpl.java
│ ├── resources
│ │ ├── META-INF
│ │ │ ├── base-spring.xml
│ │ │ ├── cluster-spring.xml
│ │ │ ├── dynamic-data-source-spring.xml
│ │ │ ├── hibernate-spring.xml
│ │ │ ├── infrastructure-spring.xml
│ │ │ ├── portlet-hbm.xml
│ │ │ ├── portlet-model-hints.xml
│ │ │ ├── portlet-orm.xml
│ │ │ ├── portlet-spring.xml
│ │ │ └── shard-data-source-spring.xml
│ │ ├── portlet.properties
│ │ └── service.properties
│ └── webapp
│ ├── css
│ │ └── main.css
│ ├── icon.png
│ ├── js
│ │ ├── main.js
│ │ └── service.js
│ ├── view.jsp
│ └── WEB-INF
│ ├── liferay-display.xml
│ ├── liferay-plugin-package.properties
│ ├── liferay-portlet.xml
│ ├── portlet.xml
│ ├── service.xml
│ ├── service.xml~
│ ├── sql
│ │ ├── indexes.properties
│ │ ├── indexes.sql
│ │ ├── sequences.sql
│ │ └── tables.sql
│ └── web.xml
└── service-portlet-service
├── pom.xml
└── src
└── main
└── java
└── com
└── my
└── cms
└── service
├── ClpSerializer.java
├── messaging
│ └── ClpMessageListener.java
├── MyServiceLocalService.java
├── MyServiceLocalServiceClp.java
├── MyServiceLocalServiceUtil.java
├── MyServiceLocalServiceWrapper.java
├── MyServiceService.java
├── MyServiceServiceClp.java
├── MyServiceServiceUtil.java
└── MyServiceServiceWrapper.java
27 directories, 48 files
Now, everything is in place to add our custom sql. you can read about custom-sql in the manual
Custom-SQL
In order to use custom SQL you need to add a file containing your SQL queries, then to add a persistence class that will call execute that query. And call the method in a sevice util class.
SQL File
The file must be called custom-sql/default.xml and contain the SQL in a CDATA section:
<custom-sql>
<sql id="fr.meteo.cms.service.persistence.MeteoJournalArticleFinder.findLatestArticleByTagName">
<![CDATA[
SELECT ja.*
FROM mf3_liferay.journalarticle AS ja
JOIN (
SELECT SUBSTRING_INDEX(GROUP_CONCAT(uuid_ ORDER BY version DESC),',',1) AS uuid_LastVersion
FROM mf3_liferay.journalarticle ja
INNER JOIN mf3_liferay.assetentry ae
ON ja.resourcePrimKey = ae.classPK
INNER JOIN mf3_liferay.assetentries_assettags ae_at
ON ae.entryId = ae_at.entryId
INNER JOIN mf3_liferay.assettag tags
ON ae_at.tagId = tags.tagId
WHERE tags.name = ?
GROUP BY articleId
ORDER BY articleId DESC
) AS uuids
ON ja.uuid_ = uuids.uuid_LastVersion
]]>
</sql>
</custom-sql> Two points of attention here :
The file needs to be put in the portlet resource dir: service/service-portlet/src/main/resources/custom-sql/default.xml
The id attribute must contain the correct package name fr.meteo.cms.service.persistence.MeteoJournalArticleFinder + a unique name for the query: findLatestArticleByTagName
Persistence class
You need to add an implementation of the persistence class, the class that will implement the execution of the SQL query. The class need to be in that package: com.my.cms.service.persistence and in that path: service\service-portlet\src\main\java\com\my\cms\service\persistence\MyServiceFinderImpl.java
package com.my.cms.service.persistence;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import com.liferay.portlet.journal.model.JournalArticle;
public class MyServiceFinderImpl extends BasePersistenceImpl {
}
You need to pay attention to the name of the class, it must be MyServiceFinderImpl or liferay will not recognize it! and it must be in the right package.
When you have put the file in the persistence forlder in the portlet package, you need to run Service Builder again to get the stubs file generated.
mvn liferay:build-service
service
├── pom.xml
├── service.iml
├── service-portlet
│ ├── pom.xml
│ ├── service-portlet.iml
│ └── src
│ └── main
│ ├── java
│ │ └── com
│ │ └── my
│ │ └── cms
│ │ └── service
│ │ ├── base
│ │ │ ├── MyServiceLocalServiceBaseImpl.java
│ │ │ ├── MyServiceLocalServiceClpInvoker.java
│ │ │ ├── MyServiceServiceBaseImpl.java
│ │ │ └── MyServiceServiceClpInvoker.java
│ │ ├── http
│ │ │ └── MyServiceServiceSoap.java
│ │ ├── impl
│ │ │ ├── MyServiceLocalServiceImpl.java
│ │ │ └── MyServiceServiceImpl.java
│ │ └── persistence
│ │ └── MyServiceFinderImpl.java
│ ├── resources
│ │ ├── custom-sql
│ │ │ └── default.xml
│ │ ├── META-INF
│ │ │ ├── base-spring.xml
│ │ │ ├── cluster-spring.xml
│ │ │ ├── dynamic-data-source-spring.xml
│ │ │ ├── hibernate-spring.xml
│ │ │ ├── infrastructure-spring.xml
│ │ │ ├── portlet-hbm.xml
│ │ │ ├── portlet-model-hints.xml
│ │ │ ├── portlet-orm.xml
│ │ │ ├── portlet-spring.xml
│ │ │ └── shard-data-source-spring.xml
│ │ ├── portlet.properties
│ │ └── service.properties
│ └── webapp
│ ├── css
│ │ └── main.css
│ ├── icon.png
│ ├── js
│ │ ├── main.js
│ │ └── service.js
│ ├── view.jsp
│ └── WEB-INF
│ ├── liferay-display.xml
│ ├── liferay-plugin-package.properties
│ ├── liferay-portlet.xml
│ ├── portlet.xml
│ ├── service.xml
│ ├── service.xml~
│ ├── sql
│ │ ├── indexes.properties
│ │ ├── indexes.sql
│ │ ├── sequences.sql
│ │ └── tables.sql
│ └── web.xml
└── service-portlet-service
├── pom.xml
├── service-portlet-service.iml
└── src
└── main
└── java
└── com
└── my
└── cms
└── service
├── ClpSerializer.java
├── messaging
│ └── ClpMessageListener.java
├── MyServiceLocalService.java
├── MyServiceLocalServiceClp.java
├── MyServiceLocalServiceUtil.java
├── MyServiceLocalServiceWrapper.java
├── MyServiceService.java
├── MyServiceServiceClp.java
├── MyServiceServiceUtil.java
├── MyServiceServiceWrapper.java
└── persistence
├── MyServiceFinder.java
└── MyServiceFinderUtil.java
30 directories, 55 files liferay added or modified those files:
service/service-portlet/src/main/webapp/WEB-INF/sql/tables.sql
service/service-portlet/src/main/resources/service.properties
service/service-portlet/src/main/java/com/my/cms/service/base/MyServiceLocalServiceClpInvoker.java
service/service-portlet/src/main/java/com/my/cms/service/base/MyServiceServiceBaseImpl.java
service/service-portlet/src/main/java/com/my/cms/service/base/MyServiceServiceClpInvoker.java
service/service-portlet/src/main/resources/META-INF/portlet-spring.xml
service/service-portlet/src/main/java/com/my/cms/service/base/MyServiceLocalServiceBaseImpl.java
service/service-portlet-service/src/main/java/com/my/cms/service/persistence/MyServiceFinder.java
service/service-portlet-service/src/main/java/com/my/cms/service/persistence/MyServiceFinderUtil.java
You can now implements the method findLatestArticleByTagName in the MyServiceFinderImpl file
package com.my.cms.service.persistence;
import com.liferay.portal.kernel.bean.PortalBeanLocatorUtil;
import com.liferay.portal.kernel.dao.orm.*;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import com.liferay.portlet.journal.model.JournalArticle;
import com.liferay.util.dao.orm.CustomSQLUtil;
import java.util.List;
public class MyServiceFinderImpl extends BasePersistenceImpl implements MyServiceFinder {
public List findLatestArticleByTagName(
String tagName,
int begin, int end) {
Session session = null;
try {
SessionFactory sessionFactory = (SessionFactory) PortalBeanLocatorUtil.locate("liferaySessionFactory");
session = sessionFactory.openSession();
String sql = CustomSQLUtil.get(
FIND_BY_LATEST_ARTICLES_BY_TAGNAME);
SQLQuery q = session.createSQLQuery(sql);
q.setCacheable(false);
q.addEntity("JournalArticle_JournalArticle", PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portlet.journal.model.impl.JournalArticleImpl"));
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(tagName);
return (List) QueryUtil.list(q, getDialect(), begin, end);
} catch (Exception e) {
try {
throw new SystemException(e);
} catch (SystemException se) {
se.printStackTrace();
}
} finally {
closeSession(session);
}
return null;
}
public static final String FIND_BY_LATEST_ARTICLES_BY_TAGNAME =
MyServiceFinder.class.getName() +
".findLatestArticleByTagName";
}
I you want to use an existing session and connect your service to it, you can use that line of code:
SessionFactory sessionFactory = (SessionFactory) PortalBeanLocatorUtil.locate("liferaySessionFactory"); You can find the entity you are looking for by using the class loader:
PortalClassLoaderUtil.getClassLoader().loadClass("com.liferay.portlet.journal.model.impl.JournalArticleImpl") Then launch again the Service Builder in order to propagate the findLatestArticleByTagName method
mvn liferay:build-service You need now to add the method in the com.my.cms.service.impl.MyServiceLocalServiceImpl class in order to use it.
public List findLatestArticleByTagName(
String tagName,
int begin, int end) {
return MyServiceFinderUtil.findLatestArticleByTagName(tagName, begin, end);
}
Then launch again the Service Builder in order to propagate the findLatestArticleByTagName method in different classes.
mvn liferay:build-service
Use the service in a portlet
In order to use the service in the portlet, you need to do some configuration first.
Add the dependency to the Service’s portlet in liferay(service/service-portlet/src/main/webapp/WEB-INF/liferay-plugin-package.properties), this will ensure that the portlet using the service will not be deployed before the service:
required-deployment-contexts=service-portlet
Add the dependency to the Service’s portlet in maven in order to get the JAR file:
<dependency>
<groupId>com.my.cms</groupId>
<artifactId>service-portlet-service</artifactId>
<version>${pom.version}</version>
</dependency> Rebuild and redeploy the service in liferay application server.
You can test your service in your portlet using the Util class:
List journalArticles = MyServiceLocalServiceUtil.findLatestArticleByTagName("actualités de recherche", currentPage, currentPage + 8);