Using service builder generated classes in other modules - liferay

I'm using Liferay 7.1 GA1 Version. I have generated my service/api java classes with service-builder that Liferay IDE provides me.
How can I use these service classes in my other modules? I would like to use "MyServiceBuilder" generated classes in "MyPortlet" like you can see in the following picture.
Thanks.
Picture

Structure your project like this:
in the gradle file of the portlet add:
compileOnly project(":modules:test-service:test-service-api")
Right click and select Gradle > Refresh Gradle Project on the test-service folder.
Then use OSGi Declarative Services in your portlet:
#Reference
protected FooLocalService _fooLocalService;

Related

I create a project and don't find the javax.servlet when I use eclipse

I generated a maven project and imported my entities. the aplicattion work perfect but if I close the IDE(eclipse) and I open again . it's said me this error.
I don't touch anythings on code. I don't understad why don't work.
https://ibb.co/NVgTb8Hn (the picture)
thanks
I think you should try with
with Maven IDE profile
If you are using Maven, you need to activate the IDE profile in Eclipse. This is used for applying IDE-specific tweaks, which currently only includes applying the MapStruct annotation processor.
Right click on Project -> Properties -> Maven
In “Active Maven Profiles”, type dev,IDE
With this configuration, you will be using both the JHipster dev and IDE profiles.

Simple calender Liferay hook gives compiler errors

first intro: I try to get a hook running on a new Liferay 6.1.2 GA3. Previously I was using the portlet plugin mechanism only.
I try to get a simple calendar hook running and get compiler errors, such as "CalEvent cannot be resolved as a type".
My feeling is that I am missing the entire Liferay libraries in the hook, but the included libraries look complete to me (in order of build path priority):
- ear libraries
- Java JDK 6
- Liferay Hook Plugin API
- Liferay V6.1 CE (Tomcat 7)
- Web App Libraries
The libraries got automatically selected when creating the project as a hook. Any ideas?
com.liferay.portlet.calendar.model.CalEvent is in portal-service.jar. This should be on the classpath of your hook and Liferay IDE/DevStudio typically adds this library when you create a new hook. If it's not there, add it. You'll find it on the global classpath of your tomcat installation, e.g. ${liferay.home}/tomcat/lib/ext - assuming that you develop on tomcat.
If you need to add this file to the project, make sure it doesn't get packaged in the plugin's WEB-INF/lib folder - it needs to be picked up from the global classpath when deployed.
You do get the errors during development time (e.g. in IDE), not when you're deploying, right?
Or is it as simple as a forgotten "organize imports"?

Liferay - Share Utils class between 2 different portlets

I'm developing a Liferay application, consisting on 2 different portlets, an both have to make certain operations in common, so I decided to put that operations in static methods in an external Utils class.
I have to externalize that class to avoid duplicating the same code in both portlets, and I want to have the portlets in different WAR files.
I know I can package the Utils class in a JAR file, but we are still developing and we don't want to regenerate the JAR and restart the Tomcat for every change.
Which is the best option and how can I perform it?
If you're using the Liferay SDK, you can use the clients (recently changed to shared) directory to put your common code.
A good example is how deploy-listener-shared is used in conjunction with deploy-listener-hook.
From what it looks like, all the configuration you need to do is to modify your build.xml files that will use the client\shared classes. If you look at build file of deploy-listener-hook you can see all you need to add is the.
For the new SDK:
<property name="import.shared" value="my-utils-shared" />
For the older SDK:
<property name="dependent.clients" value="my-utils-client" />
Hope this helps!
There is another method that involves building a JAR file but it doesn't require a server restart (on Tomcat at least).
Write a build script for your JAR file so it compiles, builds the JAR and finally copies it to the following location:
{tomcat}/webapps/ROOT/WEB-INF/lib
Then in your portlet open the "liferay-plugin-package.properties" (in Liferay Developer Studio / Liferay IDE this should open with a nice GUI).
Then add the name of your JAR to the "portal-dependency-jars" list in this file so in the source it would like (Or just hit the "Add" button in the GUI and select the JARs you want):
portal-dependency-jars=my-custom-lib.jar,my-other-custom-lib.jar
Save the file, and redeploy the portlet, and the JAR will be copied across when the portlet is deployed.
I've used this method for custom JARs, and 3rd party JARs that I've needed to use in my portlets.
For the development phase just package the jar file with both applications.
Unless one application depends on the other somehow it is completely ok.
Another solution is to use JRebel tool. It will allow you to redeploy jar in tomcat without restarting.
Also you may have several portlets in one .war. You may just define them both in portlet.xml.

Liferay 6.1: Class not found with DynamicQuery

I have a portlet project that needs to do some Group querying. I've not created the project but it was made with the Eclipse Liferay SDK plugin.
I've added a DynamicQueryFactoryUtil.forClass(Group.class) but it fails in runtime. It complains about not finding GroupImpl.class, which is implementation for interface Group. My project dependencies doesn't include portlet-impl (it contains GroupImpl.class).
I'm not sure if I should:
include that jar into dependencies for compiling
include that jar into portlet jar
Or I'm doing something wrong and querying groups would be available right out of the box.
PS: I'm pretty newbie in Liferay things...
PS2: It's Liferay 6.1
To enable Liferay to retrieve the right class, you need to provide a correct classloader to the initialization of your DynamicQuery, in this case the portal's classloader because that one has access to the model implementations:
DynamicQueryFactoryUtil.forClass(Group.class, PortalClassLoaderUtil.getClassLoader())

Dynamic Web Project with Seam Faces

I tried to start a new dynamic Web Project with Seam-Faces(Eclipse). I created a new JSF-Facility and addeed all the jar-Files from the official Seam-Faces homepage. When i try to create a dynamic web project eclipse says that the following File ist not found:
javax.faces.FactoryFinder
What i am doing wrong ? Is ist possible to use Seam-Faces without the Seam-Framework ?
There is not a Seam Framework anymore. Seam 3 is a bunch of reusable CDI extensions that you could use. The best way to start with Seam3 modules is to use maven for library management. More info about how to configure seam-faces dependencies can be found here.
For the exception you're facing make sure there are no jsf jars in WEB-INF\lib in case you're using a Java EE server like JBoss AS or Glassfish. For more info look here.

Resources