Fórum

How to add the runtime libraries to the build path of a project

Iñaki Bergara, modificado 6 Anos atrás.

How to add the runtime libraries to the build path of a project

Junior Member Postagens: 65 Data de Entrada: 30/10/11 Postagens Recentes
I'm working on a service builder module, but I've noticed some unresolved types that had me puzzled for a while. The clearest example are Language util methods:
LanguageUtil.format(locale, "counter.project-preannouncement");


That gives me a "The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required .class files" error on the IDE. I looked into it and I believe it's due to me missing the Liferay runtime library from the build path. At least, on my 6.2 project I didn't have the issue and that's the thing that stands out as missing from my newest project.

So I tried to add it, but when I try to set it up (right click on the module, build path -> Configure build path, libraries tab, add library and then choose server runtime) it comes up empty. On my old 6.2 project (with the old IDE) the runtimes I had set up would show there and they could be added to the project's build path. Is there something else that needs done now?

As for the runtime setup itself, I can see it via window->preferences, then server -> runtime environments. The ones I see on the old version are available as libraries, the one I see on the new version isn't. And when I go edit them, I don't see anything different between both versions.

What am I missing?
thumbnail
Andy Wu, modificado 6 Anos atrás.

RE: How to add the runtime libraries to the build path of a project

Regular Member Postagens: 195 Data de Entrada: 05/05/15 Postagens Recentes
hey could you give out some steps to reproduce this problem and it would be better if you can upload a sample project .
Iñaki Bergara, modificado 6 Anos atrás.

RE: How to add the runtime libraries to the build path of a project

Junior Member Postagens: 65 Data de Entrada: 30/10/11 Postagens Recentes
Andy Wu:
hey could you give out some steps to reproduce this problem and it would be better if you can upload a sample project .


Well, I don't recall doing anything out of the ordinary, just create the service builder module normally. But I will try to reproduce the issue in detail from a clean install and upload the result.

So, I start eclipse to a new workspace. Close the welcome screen, right click on project explorer and new -> Liferay workspace. I name it TestWorkspace and leave the rest default. This triggers the liferay perspective. Now right click on the TestWorkspace and go new->module project. I name it ServiceTest, choose service-builder as the project template name and finish.

The service builder module is created with a default entity named foo, so build services as-is. Now, I add the generated src/main/java to the build path via "use as source folder" on both the service and the api modules. And finally, I write some code on FooLocalServiceImpl.java
import java.util.Locale;
import com.liferay.portal.kernel.language.LanguageUtil;
(...)
	Locale locale;
	String test = LanguageUtil.format(locale, "key.test",42);


Now, I get an error on LanguageUtil.format that reads "The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required .class files". This is my problem.

In order to solve it, I try to add the runtime libraries. So first I set up the runtime. From top menu, window->preferences. Now, tab server->runtime environment. Click on add, choose liferay 7.x, leave the name default and browse the Liferay Portal Bundle Directory to a folder with an extraction of liferay ce portal 7.0 ga3. The portal bundle type is correctly detected to be tomcat, and the selected runtime JRE is jre1.8.0_121. Then I finish.

Now I have the liferay 7 runtime environment on the list, so I press OK. I now go to the project explorer and I right click the ServiceTest-service module, choose build path -> configure build path. Go to the libraries tab, click on the add library button; then I select "server runtime" from the list and it's empty. I would expect to see my liferay 7 runtime there, which I would expect would solve my import problem.

I am attaching a rar of the entire resulting workspace, hopefully that will be of service.
thumbnail
David H Nebinger, modificado 6 Anos atrás.

RE: How to add the runtime libraries to the build path of a project

Liferay Legend Postagens: 14916 Data de Entrada: 02/09/06 Postagens Recentes
You're missing your dependency declarations in build.gradle.

Here's an example where I'm just needing the OSGi and the kernel interfaces plus my API jar:

dependencies {
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.4.0"
    compileOnly group: "org.osgi", name: "org.osgi.core", version: "6.0.0"
    compileOnly group: "org.osgi", name: "org.osgi.service.component.annotations", version: "1.3.0"
    compileOnly project(':modules:apps:filesystem-access-api')
}


As you add more 3rd party things, you have to add the dependencies in this file to pull them in.





Come meet me at the 2017 LSNA!
thumbnail
Andy Wu, modificado 6 Anos atrás.

RE: How to add the runtime libraries to the build path of a project (Resposta)

Regular Member Postagens: 195 Data de Entrada: 05/05/15 Postagens Recentes
got it , adding following dependency to build.gradle is ok :

compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"

cause LanguageUtil.java in portal.kernel will import javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse
see https://github.com/liferay/liferay-portal/blob/master/portal-kernel/src/com/liferay/portal/kernel/language/LanguageUtil.java#L32-L33
Iñaki Bergara, modificado 6 Anos atrás.

RE: How to add the runtime libraries to the build path of a project

Junior Member Postagens: 65 Data de Entrada: 30/10/11 Postagens Recentes
Andy Wu:
got it , adding following dependency to build.gradle is ok :

compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"

cause LanguageUtil.java in portal.kernel will import javax.servlet.http.HttpServletRequest and javax.servlet.http.HttpServletResponse
see https://github.com/liferay/liferay-portal/blob/master/portal-kernel/src/com/liferay/portal/kernel/language/LanguageUtil.java#L32-L33


Thanks, that does let me build it, but I still get an error on the IDE. It seems that I was going the right route, according to this to add this dependency I do have to add the server runtime to the project, and after I saw the error disappear from eclipse I would have to add the dependency to gradle because it would not have built.

I can go on ignoring the errors on eclipse, but it would be nice to eliminate them. It would also be nice if Liferay IDE automatically kept the gradle and eclipse project dependencies in sync, but that may just be wishful thinking.
thumbnail
Andy Wu, modificado 6 Anos atrás.

RE: How to add the runtime libraries to the build path of a project

Regular Member Postagens: 195 Data de Entrada: 05/05/15 Postagens Recentes
I don't know why you have to add server runtime to project , cause add dependency to gradle is enough, and by the way , after adding to gradle , you should right click the project and go to "Gradle->refresh gradle project" to sync dependencies.
Iñaki Bergara, modificado 6 Anos atrás.

RE: How to add the runtime libraries to the build path of a project

Junior Member Postagens: 65 Data de Entrada: 30/10/11 Postagens Recentes
Andy Wu:
I don't know why you have to add server runtime to project , cause add dependency to gradle is enough, and by the way , after adding to gradle , you should right click the project and go to "Gradle->refresh gradle project" to sync dependencies.



Because I didn't see that sync option, so I had to handle the eclipse and gradle dependencies separately. Which is no longer necessary. Thanks again.