掲示板

RE: Java class import Error !

thumbnail
9年前 に David H Nebinger によって更新されました。

RE: Java class import Error !

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Didn't we just go through in another thread where you cannot import java classes into JSP files in hooks? I could have sworn we just went through this, but in that case it was including java class within the JSP page itself (also a bad thing), but the same result...

Since the JSP file deploys to the portal's context, the java class you are trying to use must be within the portal context (and that is something hooks cannot do).

To use your own java classes in JSP hooks, the code either must be global (i.e. packaged into a jar and deployed to lib/ext in tomcat, for example) or it must be deployed via EXT plugin (to integrate it into the ROOT web app).
thumbnail
9年前 に Vitaliy Koshelenko によって更新されました。

RE: Java class import Error !

Expert 投稿: 319 参加年月日: 11/03/25 最新の投稿
Hi David,

here is a blog about using custom classes in JSP hooks:
https://www.liferay.com/web/kzhang/blog/-/blogs/using-custom-java-classes-in-a-jsp-hook

Vitaliy
thumbnail
9年前 に Jack Bakker によって更新されました。

RE: Java class import Error !

Liferay Master 投稿: 978 参加年月日: 10/01/03 最新の投稿
I think the original post which got deleted was the below
I think it was Soukaina HAJI:

Hello,
I created a java class in a hook and I imported it in asset_publisher/view.jsp
like this:
1<%@ page import="fr.irsa.liferay.hook.assetPublisher.IrsaAssetPublisherUtil"%>

and it gives this error :
1 Only a type can be imported. fr.irsa.liferay.hook.assetPublisher.IrsaAssetPublisherUtil resolves to a package


thank you

Liferay 6.2 ce ga2
thumbnail
9年前 に David H Nebinger によって更新されました。

RE: Java class import Error !

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
Yeah, Vitally, the blog makes it seem "doable", but it certainly isn't very clean at all.

I mean, reflection in a JSP page? Or injection into the struts action as a render request attribute?

Sure, they might actually work but how fragile does the page become?

Lots of things can be hacked into Liferay, and sometimes there are absolute times where it's the only way to do something, I try not to advocate jumping to a hack right away because most people (especially newbies) don't fully understand the consequences of doing so. I feel it's better to advocate for the tried and true, approved ways of getting things done...