Re: How to package java classes in an opencms module
"laurent.druart via opencms-dev" <[email protected]> Fri, 8 Aug 2025 15:27:14 +0200
| Newsgroups | gmane.comp.cms.opencms.devel |
|---|---|
| Message-ID | <[email protected]> |
--===============8253619940584015241==
Content-Type: multipart/alternative;
boundary="Apple-Mail=_F5F8C2DF-EE40-4E5D-B71F-DE0AF887C22D"
--Apple-Mail=_F5F8C2DF-EE40-4E5D-B71F-DE0AF887C22D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=utf-8
Hello Michael,
Thank you for your answer.
The goal of java classes in a module is automatic creation of my context =
on OpenCMS startup, that=E2=80=99s why I implemented=20
LibraryInitializer extends A_CmsModuleAction implements =
I_CmsEventListener
In a previous test I had a section =C2=AB resources =C2=BB like this
<resources>
<resource uri=3D"/system/modules/com.opencms.library/"/>
</resources>
but not working at all.
So I=E2=80=99ve to create a file section per class in my module? =
Documentation is not clear on manifest.xml. Do you have an exemple with =
java classes and lib dependencies?
Thanks a lot.
Kind regards,
Laurent
> Le 8 ao=C3=BBt 2025 =C3=A0 14:30, Michael Emmerich via opencms-dev =
<[email protected]> a =C3=A9crit :
>=20
> Laurent,
>=20
> from you manifest, I see that you have not assigned any resources to =
your module. So no resources are imported when you import the module, =
therefore the .jar and .classes are missing. I see that you have =
defined the export points, but without the imported file, this will not =
work.
>=20
> However, we usually do not put .jar or .class files in our modules, we =
deploy them separately on the server as yo have to restart it anyway =
after deploying some .jar and .class files.
>=20
>=20
> Kind regards,
>=20
> Michael
>=20
>=20
>=20
> Am 08.08.25 um 11:22 schrieb laurent.druart via opencms-dev:
>> Hello,
>>=20
>> In add-on to my previous e-mail, here is the content/structure of my =
zip files :
>>=20
>>=20
>> And the content of my manifest.xml :
>>=20
>> <?xml version=3D"1.0" encoding=3D"UTF-8"?>
>> <export>
>> <info>
>> <creator>OpenCMS Module Builder</creator>
>> <opencms_version>19.0</opencms_version>
>> <createdate>Wed, 07 Aug 2025 10:00:00 GMT</createdate>
>> <project>Offline</project>
>> <export_version>7</export_version>
>> </info>
>>=20
>> <module>
>> <name>com.opencms.library</name>
>> <nicename>OpenCMS Spring Data JDBC Library</nicename>
>> <group>Custom Libraries</group>
>> =
<class>com.opencms.library.integration.LibraryInitializer</class>
>> <description>Librairie Spring classique pour OpenCMS avec =
acc=C3=A8s aux donn=C3=A9es PostgreSQL</description>
>> <version>1.0.0</version>
>> <authorname>Laurent Druart</authorname>
>> <authoremail>[email protected]</authoremail>
>> <datecreated>Wed, 07 Aug 2025 10:00:00 GMT</datecreated>
>> <userinstalled>Admin</userinstalled>
>> <dateinstalled>Wed, 07 Aug 2025 10:00:00 GMT</dateinstalled>
>>=20
>> <dependencies/>
>>=20
>> <exportpoints>
>> <exportpoint =
uri=3D"/system/modules/com.opencms.library/classes/" =
destination=3D"WEB-INF/classes/"/>
>> <exportpoint =
uri=3D"/system/modules/com.opencms.library/lib/" =
destination=3D"WEB-INF/lib/"/>
>> </exportpoints>
>> <resources/>
>> <parameters>
>> <param name=3D"spring.auto.init">true</param>
>> </parameters>
>> </module>
>>=20
>> <files/>
>> </export>
>>=20
>> I tried to import the zip in the modules app, module is created but =
classes and lib are not copied in WEB-INF folders and in the explorer =
app there are no =C2=AB com.opencms.library =C2=BB entries in =
/system/modules
>>=20
>> Thanks for your help.
>>=20
>> Regards,
>>=20
>> Laurent
>>=20
>>> Le 7 ao=C3=BBt 2025 =C3=A0 16:41, laurent.druart via opencms-dev =
<[email protected]> a =C3=A9crit :
>>>=20
>>> Hello,
>>>=20
>>> I=E2=80=99m still testing OpenCMS and i wrote a very small library, =
a spring based library. I want to use the beans in my jsp so i wrote 2 =
classes:
>>>=20
>>> SpringBeanUtils :
>>>=20
>>> public class SpringBeanUtils {
>>>=20
>>> private static final Log LOG =3D =
CmsLog.getLog(SpringBeanUtils.class);
>>>=20
>>> /**
>>> * R=C3=A9cup=C3=A8re le service utilisateur
>>> * Exemple d'utilisation dans une page JSP :
>>> * <%
>>> * UserService userService =3D =
SpringBeanUtils.getUserService();
>>> * List<User> users =3D userService.getAllActiveUsers();
>>> * %>
>>> */
>>> public static UserService getUserService() {
>>> try {
>>> return LibraryInitializer.getBean(UserService.class);
>>> } catch (Exception e) {
>>> LOG.error("Erreur lors de la r=C3=A9cup=C3=A9ration du =
UserService", e);
>>> throw new RuntimeException("Service utilisateur non =
disponible", e);
>>> }
>>> }
>>>=20
>>> /**
>>> * M=C3=A9thode g=C3=A9n=C3=A9rique pour r=C3=A9cup=C3=A9rer =
n'importe quel service
>>> * Exemple :
>>> * MyService service =3D =
SpringBeanUtils.getService(MyService.class);
>>> */
>>> public static <T> T getService(Class<T> serviceClass) {
>>> try {
>>> return LibraryInitializer.getBean(serviceClass);
>>> } catch (Exception e) {
>>> LOG.error("Erreur lors de la r=C3=A9cup=C3=A9ration du =
service: " + serviceClass.getSimpleName(), e);
>>> throw new RuntimeException("Service non disponible: " + =
serviceClass.getSimpleName(), e);
>>> }
>>> }
>>>=20
>>> /**
>>> * R=C3=A9cup=C3=A8re un bean par son nom
>>> * Exemple :
>>> * Object bean =3D SpringBeanUtils.getBean("userService");
>>> */
>>> public static Object getBean(String beanName) {
>>> try {
>>> return LibraryInitializer.getBean(beanName);
>>> } catch (Exception e) {
>>> LOG.error("Erreur lors de la r=C3=A9cup=C3=A9ration du =
bean: " + beanName, e);
>>> throw new RuntimeException("Bean non disponible: " + =
beanName, e);
>>> }
>>> }
>>>=20
>>> /**
>>> * V=C3=A9rifie si le contexte Spring est disponible
>>> */
>>> public static boolean isAvailable() {
>>> return LibraryInitializer.isSpringContextAvailable();
>>> }
>>>=20
>>> /**
>>> * M=C3=A9thode utilitaire pour v=C3=A9rifier la disponibilit=C3=A9=
avant utilisation
>>> */
>>> public static void ensureAvailable() {
>>> if (!isAvailable()) {
>>> throw new IllegalStateException(
>>> "Le contexte Spring n'est pas disponible. " +
>>> "V=C3=A9rifiez que le module est =
correctement initialis=C3=A9."
>>> );
>>> }
>>> }
>>> }
>>>=20
>>> with static method getUserService() I can call the userService bean. =
No problem with it.
>>>=20
>>> And second class LibraryInitializer wich must initialise the spring =
context and configure it:
>>>=20
>>> public class LibraryInitializer extends A_CmsModuleAction implements =
I_CmsEventListener {
>>>=20
>>> private static final String MODULE_NAME =3D =
"opencms-spring-library";
>>> private static ApplicationContext springContext;
>>> private static final org.apache.commons.logging.Log LOG =3D =
CmsLog.getLog(LibraryInitializer.class);
>>>=20
>>> /**
>>> * Initialisation du module
>>> */
>>> @Override
>>> public void initialize(org.opencms.file.CmsObject adminCms,
>>> =
org.opencms.configuration.CmsConfigurationManager configurationManager,
>>> CmsModule module) {
>>>=20
>>> LOG.info("Initialisation de la librairie Spring classique =
pour OpenCMS");
>>>=20
>>> try {
>>> // Configuration des propri=C3=A9t=C3=A9s syst=C3=A8me
>>> configureSystemProperties();
>>>=20
>>> // Cr=C3=A9ation du contexte Spring CLASSIQUE
>>> AnnotationConfigApplicationContext context =3D new =
AnnotationConfigApplicationContext();
>>> =
context.register(com.opencms.library.config.LibraryConfiguration.class);
>>> context.refresh();
>>>=20
>>> springContext =3D context;
>>>=20
>>> // Enregistrement des listeners OpenCMS
>>> OpenCms.addCmsEventListener(this);
>>>=20
>>> LOG.info("Librairie Spring classique initialis=C3=A9e =
avec succ=C3=A8s");
>>>=20
>>> } catch (Exception e) {
>>> LOG.error("Erreur lors de l'initialisation de la =
librairie Spring", e);
>>> throw new RuntimeException("Impossible d'initialiser la =
librairie Spring", e);
>>> }
>>> }
>>>=20
>>> /**
>>> * Arr=C3=AAt du module
>>> */
>>> @Override
>>> public void shutDown(CmsModule module) {
>>> LOG.info("Arr=C3=AAt de la librairie Spring classique");
>>>=20
>>> if (springContext !=3D null) {
>>> try {
>>> if (springContext instanceof =
AnnotationConfigApplicationContext) {
>>> ((AnnotationConfigApplicationContext) =
springContext).close();
>>> }
>>> LOG.info("Contexte Spring ferm=C3=A9 avec succ=C3=A8s")=
;
>>> } catch (Exception e) {
>>> LOG.error("Erreur lors de l'arr=C3=AAt du contexte =
Spring", e);
>>> } finally {
>>> springContext =3D null;
>>> }
>>> }
>>> }
>>>=20
>>> /**
>>> * Gestion des =C3=A9v=C3=A9nements OpenCMS
>>> */
>>> @Override
>>> public void cmsEvent(CmsEvent event) {
>>> switch (event.getType()) {
>>> case I_CmsEventListener.EVENT_PUBLISH_PROJECT:
>>> LOG.debug("=C3=89v=C3=A9nement de publication =
d=C3=A9tect=C3=A9");
>>> break;
>>> case I_CmsEventListener.EVENT_CLEAR_CACHES:
>>> LOG.debug("=C3=89v=C3=A9nement de nettoyage des =
caches d=C3=A9tect=C3=A9");
>>> break;
>>> }
>>> }
>>>=20
>>> /**
>>> * Configuration des propri=C3=A9t=C3=A9s syst=C3=A8me
>>> */
>>> private void configureSystemProperties() {
>>> // Configuration de base de donn=C3=A9es (valeurs par =
d=C3=A9faut)
>>> if (System.getProperty("spring.datasource.url") =3D=3D null) =
{
>>> System.setProperty("spring.datasource.url", =
"jdbc:postgresql://postgres-db:5432/libdb");
>>> }
>>> if (System.getProperty("spring.datasource.username") =3D=3D =
null) {
>>> System.setProperty("spring.datasource.username", =
"appuser");
>>> }
>>> if (System.getProperty("spring.datasource.password") =3D=3D =
null) {
>>> System.setProperty("spring.datasource.password", =
"apppassword");
>>> }
>>>=20
>>> LOG.info("Propri=C3=A9t=C3=A9s syst=C3=A8me configur=C3=A9es");=
>>> }
>>>=20
>>> /**
>>> * Acc=C3=A8s aux beans Spring
>>> */
>>> public static <T> T getBean(Class<T> beanClass) {
>>> if (springContext =3D=3D null) {
>>> throw new IllegalStateException("Le contexte Spring n'est =
pas initialis=C3=A9");
>>> }
>>> return springContext.getBean(beanClass);
>>> }
>>>=20
>>> public static Object getBean(String beanName) {
>>> if (springContext =3D=3D null) {
>>> throw new IllegalStateException("Le contexte Spring n'est =
pas initialis=C3=A9");
>>> }
>>> return springContext.getBean(beanName);
>>> }
>>>=20
>>> public static boolean isSpringContextAvailable() {
>>> return springContext !=3D null;
>>> }
>>> }
>>>=20
>>> If i build this lib as a jar and put it in WEB-INF/lib i can access =
my beans in jsp pages but i must do this call first:
>>>=20
>>> com.opencms.library.integration.LibraryInitializer =
initializer =3D
>>> new =
com.opencms.library.integration.LibraryInitializer();
>>>=20
>>> // Appel direct de initialize avec des param=C3=A8tres =
nulls (notre version simplifi=C3=A9e les g=C3=A8re)
>>> initializer.initialize(null, null, null);
>>> after that my context is initialized and configured and my jsp are =
running fine. But the way to automatic loading of my context seems to be =
an opencms module.
>>>=20
>>> I tried to adapt my lib with opencms-module.xml, manifest.xml,... =
but nothing works: at startup =
com.opencms.library.integration.LibraryInitializer is not found by =
opencms.
>>>=20
>>> Can you help me?
>>> Does it exist a tutorial or how-to?
>>>=20
>>> Am i wrong with public class LibraryInitializer extends =
A_CmsModuleAction implements I_CmsEventListener ?
>>>=20
>>> Thank you
>>>=20
>>> Kind regards,
>>>=20
>>> Laurent
>>>=20
>>>=20
>>> _______________________________________________
>>> This mail is sent to you from the opencms-dev mailing list
>>> To change your list options, or to unsubscribe from the list, please =
visit
>>> https://lists.opencms.org/mailman/listinfo/opencms-dev
>>>=20
>>>=20
>>>=20
>>=20
>> _______________________________________________
>> This mail is sent to you from the opencms-dev mailing list
>> To change your list options, or to unsubscribe from the list, please =
visit
>> https://lists.opencms.org/mailman/listinfo/opencms-dev
>>=20
>>=20
>>=20
> --=20
> Michael Emmerich
> Alkacon Software GmbH & Co. KG - The OpenCms Experts
> http://www.alkacon.com
> http://www.opencms.org
>=20
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please =
visit
> https://lists.opencms.org/mailman/listinfo/opencms-dev
>=20
>=20
>=20
--Apple-Mail=_F5F8C2DF-EE40-4E5D-B71F-DE0AF887C22D
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=utf-8
<html><head><meta http-equiv=3D"content-type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"overflow-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;">Hello =
Michael,<div><br></div><div>Thank you for your =
answer.</div><div><br></div><div>The goal of java classes in a module is =
automatic creation of my context on OpenCMS startup, that=E2=80=99s why =
I implemented </div><div><br></div><div><pre =
style=3D"background-color: rgb(43, 43, 43); color: rgb(169, 183, 198); =
font-family: "JetBrains Mono", monospace;">LibraryInitializer =
<span style=3D"color: rgb(204, 120, 50);">extends =
</span>A_CmsModuleAction <span style=3D"color: rgb(204, 120, =
50);">implements =
</span>I_CmsEventListener</pre></div><div><br></div><div>In a previous =
test I had a section =C2=AB resources =C2=BB like =
this</div><div><br></div><div><div> =
<resources></div><div> =
<resource =
uri=3D"/system/modules/com.opencms.library/"/></div><div> =
</resources></div><div><br></div><div>but not =
working at all.</div><div><br></div><div>So I=E2=80=99ve to create a =
file section per class in my module? Documentation is not clear on =
manifest.xml. Do you have an exemple with java classes and lib =
dependencies?</div><div><br></div><div>Thanks a =
lot.</div><div><br></div><div>Kind =
regards,</div><div><br></div><div>Laurent</div><div><br><blockquote =
type=3D"cite"><div>Le 8 ao=C3=BBt 2025 =C3=A0 14:30, Michael Emmerich =
via opencms-dev <[email protected]> a =C3=A9crit :</div><br =
class=3D"Apple-interchange-newline"><div><div>Laurent,<br><br>from you =
manifest, I see that you have not assigned any resources to your module. =
So no resources are imported when you import the module, therefore the =
.jar and .classes are missing. I see that you have defined the =
export points, but without the imported file, this will not =
work.<br><br>However, we usually do not put .jar or .class files in our =
modules, we deploy them separately on the server as yo have to restart =
it anyway after deploying some .jar and .class files.<br><br><br>Kind =
regards,<br><br>Michael<br><br><br><br>Am 08.08.25 um 11:22 schrieb =
laurent.druart via opencms-dev:<br><blockquote =
type=3D"cite">Hello,<br><br>In add-on to my previous e-mail, here is the =
content/structure of my zip files :<br><br><br>And the content of my =
manifest.xml :<br><br><?xml version=3D"1.0" =
encoding=3D"UTF-8"?><br><export><br> =
<info><br> =
<creator>OpenCMS =
Module Builder</creator><br> =
<opencms_version>19.=
0</opencms_version><br> =
<createdate>Wed, =
07 Aug 2025 10:00:00 GMT</createdate><br> =
<project>Offline<=
/project><br> =
<export_version>7<=
;/export_version><br> </info><br><br> =
<module><br> =
<name>com.opencms.li=
brary</name><br> =
<nicename>OpenCMS =
Spring Data JDBC Library</nicename><br> =
<group>Custom =
Libraries</group><br> =
<class>com.opencms.l=
ibrary.integration.LibraryInitializer</class><br> =
<description>Librair=
ie Spring classique pour OpenCMS avec acc=C3=A8s aux donn=C3=A9es =
PostgreSQL</description><br> =
<version>1.0.0</v=
ersion><br> =
<authorname>Laurent =
Druart</authorname><br> =
<authoremail>laurent=
[email protected]</authoremail><br> =
<datecreated>Wed, =
07 Aug 2025 10:00:00 GMT</datecreated><br> =
<userinstalled>Admin=
</userinstalled><br> =
<dateinstalled>Wed, =
07 Aug 2025 10:00:00 GMT</dateinstalled><br><br> =
<dependencies/><br><=
br> =
<exportpoints><br> =
&l=
t;exportpoint uri=3D"/system/modules/com.opencms.library/classes/" =
destination=3D"WEB-INF/classes/"/><br> =
&l=
t;exportpoint uri=3D"/system/modules/com.opencms.library/lib/" =
destination=3D"WEB-INF/lib/"/><br> =
</exportpoints><br> =
<resources/><br> =
<parameters><br> =
&l=
t;param name=3D"spring.auto.init">true</param><br> =
</parameters><br> =
</module><br><br> =
<files/><br></export><br><br>I tried =
to import the zip in the modules app, module is created but classes and =
lib are not copied in WEB-INF folders and in the explorer app there are =
no =C2=AB com.opencms.library =C2=BB entries in =
/system/modules<br><br>Thanks for your =
help.<br><br>Regards,<br><br>Laurent<br><br><blockquote type=3D"cite">Le =
7 ao=C3=BBt 2025 =C3=A0 16:41, laurent.druart via opencms-dev =
<[email protected]> a =C3=A9crit =
:<br><br>Hello,<br><br>I=E2=80=99m still testing OpenCMS and i wrote a =
very small library, a spring based library. I want to use the beans in =
my jsp so i wrote 2 classes:<br><br>SpringBeanUtils :<br><br>public =
class SpringBeanUtils {<br><br> private static final =
Log LOG =3D CmsLog.getLog(SpringBeanUtils.class);<br><br> =
/**<br> * R=C3=A9cup=C3=A8re =
le service utilisateur<br> * Exemple =
d'utilisation dans une page JSP :<br> * =
<%<br> * UserService userService =
=3D SpringBeanUtils.getUserService();<br> * =
List<User> users =3D =
userService.getAllActiveUsers();<br> * %><br> =
*/<br> public static =
UserService getUserService() {<br> =
try {<br> =
return =
LibraryInitializer.getBean(UserService.class);<br> =
} catch (Exception e) {<br> =
LOG.erro=
r("Erreur lors de la r=C3=A9cup=C3=A9ration du UserService", e);<br> =
throw =
new RuntimeException("Service utilisateur non disponible", e);<br> =
}<br> =
}<br><br> /**<br> =
* M=C3=A9thode g=C3=A9n=C3=A9rique pour =
r=C3=A9cup=C3=A9rer n'importe quel service<br> * =
Exemple :<br> * MyService service =3D =
SpringBeanUtils.getService(MyService.class);<br> =
*/<br> public static <T> =
T getService(Class<T> serviceClass) {<br> =
try {<br> =
return =
LibraryInitializer.getBean(serviceClass);<br> =
} catch (Exception e) {<br> =
LOG.erro=
r("Erreur lors de la r=C3=A9cup=C3=A9ration du service: " + =
serviceClass.getSimpleName(), e);<br> =
throw =
new RuntimeException("Service non disponible: " + =
serviceClass.getSimpleName(), e);<br> =
}<br> =
}<br><br> /**<br> =
* R=C3=A9cup=C3=A8re un bean par son nom<br> =
* Exemple :<br> * Object =
bean =3D SpringBeanUtils.getBean("userService");<br> =
*/<br> public static Object =
getBean(String beanName) {<br> =
try {<br> =
return =
LibraryInitializer.getBean(beanName);<br> =
} catch (Exception e) {<br> =
LOG.erro=
r("Erreur lors de la r=C3=A9cup=C3=A9ration du bean: " + beanName, =
e);<br> =
throw =
new RuntimeException("Bean non disponible: " + beanName, e);<br> =
}<br> =
}<br><br> /**<br> =
* V=C3=A9rifie si le contexte Spring est =
disponible<br> */<br> public =
static boolean isAvailable() {<br> =
return =
LibraryInitializer.isSpringContextAvailable();<br> =
}<br><br> /**<br> =
* M=C3=A9thode utilitaire pour v=C3=A9rifier la =
disponibilit=C3=A9 avant utilisation<br> */<br> =
public static void ensureAvailable() {<br> =
if (!isAvailable()) {<br> =
throw =
new IllegalStateException(<br> =
&n=
bsp; "Le contexte Spring n'est pas =
disponible. " +<br> =
&n=
bsp; &nbs=
p; "V=C3=A9rifiez que le module est correctement =
initialis=C3=A9."<br> =
);<br> =
}<br> =
}<br>}<br><br>with static method getUserService() I =
can call the userService bean. No problem with it.<br><br>And second =
class LibraryInitializer wich must initialise the spring context and =
configure it:<br><br>public class LibraryInitializer extends =
A_CmsModuleAction implements I_CmsEventListener {<br><br> =
private static final String MODULE_NAME =3D =
"opencms-spring-library";<br> private static =
ApplicationContext springContext;<br> private static =
final org.apache.commons.logging.Log LOG =3D =
CmsLog.getLog(LibraryInitializer.class);<br><br> =
/**<br> * Initialisation du =
module<br> */<br> =
@Override<br> public void =
initialize(org.opencms.file.CmsObject adminCms,<br> =
&n=
bsp; &nbs=
p; org.opencms.configuration.CmsConfigurationManager =
configurationManager,<br> =
&n=
bsp; &nbs=
p; CmsModule module) {<br><br> =
LOG.info("Initialisation de la =
librairie Spring classique pour OpenCMS");<br><br> =
try {<br> =
// =
Configuration des propri=C3=A9t=C3=A9s syst=C3=A8me<br> =
configur=
eSystemProperties();<br><br> =
// =
Cr=C3=A9ation du contexte Spring CLASSIQUE<br> =
Annotati=
onConfigApplicationContext context =3D new =
AnnotationConfigApplicationContext();<br> =
context.=
register(com.opencms.library.config.LibraryConfiguration.class);<br> =
context.=
refresh();<br><br> =
springCo=
ntext =3D context;<br><br> =
// =
Enregistrement des listeners OpenCMS<br> =
OpenCms.=
addCmsEventListener(this);<br><br> =
LOG.info=
("Librairie Spring classique initialis=C3=A9e avec succ=C3=A8s");<br><br> =
} catch (Exception e) {<br> =
LOG.erro=
r("Erreur lors de l'initialisation de la librairie Spring", e);<br> =
throw =
new RuntimeException("Impossible d'initialiser la librairie Spring", =
e);<br> }<br> =
}<br><br> /**<br> =
* Arr=C3=AAt du module<br> =
*/<br> @Override<br> =
public void shutDown(CmsModule module) {<br> =
LOG.info("Arr=C3=AAt de la =
librairie Spring classique");<br><br> =
if (springContext !=3D null) =
{<br> =
try =
{<br> =
&n=
bsp; if (springContext instanceof =
AnnotationConfigApplicationContext) {<br> =
&n=
bsp; ((AnnotationConfigApplicationConte=
xt) springContext).close();<br> =
&n=
bsp; }<br> =
&n=
bsp; LOG.info("Contexte Spring ferm=C3=A9 avec succ=C3=A8s");<b=
r> } =
catch (Exception e) {<br> =
&n=
bsp; LOG.error("Erreur lors de l'arr=C3=AAt du contexte =
Spring", e);<br> =
} =
finally {<br> =
&n=
bsp; springContext =3D null;<br> =
}<br> =
}<br> =
}<br><br> /**<br> =
* Gestion des =C3=A9v=C3=A9nements OpenCMS<br> =
*/<br> @Override<br> =
public void cmsEvent(CmsEvent event) {<br> =
switch (event.getType()) {<br> =
case =
I_CmsEventListener.EVENT_PUBLISH_PROJECT:<br> =
&n=
bsp; LOG.debug("=C3=89v=C3=A9nement de publication =
d=C3=A9tect=C3=A9");<br> =
&n=
bsp; break;<br> =
case =
I_CmsEventListener.EVENT_CLEAR_CACHES:<br> =
&n=
bsp; LOG.debug("=C3=89v=C3=A9nement de nettoyage des caches =
d=C3=A9tect=C3=A9");<br> =
&n=
bsp; break;<br> =
}<br> =
}<br><br> /**<br> =
* Configuration des propri=C3=A9t=C3=A9s =
syst=C3=A8me<br> */<br> =
private void configureSystemProperties() {<br> =
// Configuration de base de =
donn=C3=A9es (valeurs par d=C3=A9faut)<br> =
if =
(System.getProperty("spring.datasource.url") =3D=3D null) {<br> =
System.s=
etProperty("spring.datasource.url", =
"jdbc:postgresql://postgres-db:5432/libdb");<br> =
}<br> =
if =
(System.getProperty("spring.datasource.username") =3D=3D null) {<br> =
System.s=
etProperty("spring.datasource.username", "appuser");<br> =
}<br> =
if =
(System.getProperty("spring.datasource.password") =3D=3D null) {<br> =
System.s=
etProperty("spring.datasource.password", "apppassword");<br> =
}<br><br> =
LOG.info("Propri=C3=A9t=C3=A9s =
syst=C3=A8me configur=C3=A9es");<br> }<br><br> =
/**<br> * Acc=C3=A8s aux beans =
Spring<br> */<br> public =
static <T> T getBean(Class<T> beanClass) {<br> =
if (springContext =3D=3D null) =
{<br> =
throw =
new IllegalStateException("Le contexte Spring n'est pas =
initialis=C3=A9");<br> }<br> =
return =
springContext.getBean(beanClass);<br> }<br><br> =
public static Object getBean(String beanName) {<br> =
if (springContext =3D=3D null) =
{<br> =
throw =
new IllegalStateException("Le contexte Spring n'est pas =
initialis=C3=A9");<br> }<br> =
return =
springContext.getBean(beanName);<br> }<br><br> =
public static boolean isSpringContextAvailable() {<br> =
return springContext !=3D =
null;<br> }<br>}<br><br>If i build this lib as a jar =
and put it in WEB-INF/lib i can access my beans in jsp pages but i must =
do this call first:<br><br> =
com.opencms.li=
brary.integration.LibraryInitializer initializer =3D<br> =
&n=
bsp; new =
com.opencms.library.integration.LibraryInitializer();<br><br> =
// =
Appel direct de initialize avec des param=C3=A8tres nulls (notre version =
simplifi=C3=A9e les g=C3=A8re)<br> =
initiali=
zer.initialize(null, null, null);<br>after that my context is =
initialized and configured and my jsp are running fine. But the way to =
automatic loading of my context seems to be an opencms module.<br><br>I =
tried to adapt my lib with opencms-module.xml, manifest.xml,... but =
nothing works: at startup =
com.opencms.library.integration.LibraryInitializer is not found by =
opencms.<br><br>Can you help me?<br>Does it exist a tutorial or =
how-to?<br><br>Am i wrong with public class LibraryInitializer extends =
A_CmsModuleAction implements I_CmsEventListener ?<br><br>Thank =
you<br><br>Kind =
regards,<br><br>Laurent<br><br><br>_______________________________________=
________<br>This mail is sent to you from the opencms-dev mailing =
list<br>To change your list options, or to unsubscribe from the list, =
please =
visit<br>https://lists.opencms.org/mailman/listinfo/opencms-dev<br><br><br=
><br></blockquote><br>_______________________________________________<br>T=
his mail is sent to you from the opencms-dev mailing list<br>To change =
your list options, or to unsubscribe from the list, please =
visit<br>https://lists.opencms.org/mailman/listinfo/opencms-dev<br><br><br=
><br></blockquote>-- <br>Michael Emmerich<br> Alkacon Software GmbH =
& Co. KG - The OpenCms =
Experts<br>http://www.alkacon.com<br>http://www.opencms.org<br><br>_______=
________________________________________<br>This mail is sent to you =
from the opencms-dev mailing list<br>To change your list options, or to =
unsubscribe from the list, please =
visit<br>https://lists.opencms.org/mailman/listinfo/opencms-dev<br><br><br=
><br></div></div></blockquote></div><br></div></body></html>=
--Apple-Mail=_F5F8C2DF-EE40-4E5D-B71F-DE0AF887C22D--
--===============8253619940584015241==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline
X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVGhpcyBtYWls
IGlzIHNlbnQgdG8geW91IGZyb20gdGhlIG9wZW5jbXMtZGV2IG1haWxpbmcgbGlzdApUbyBjaGFu
Z2UgeW91ciBsaXN0IG9wdGlvbnMsIG9yIHRvIHVuc3Vic2NyaWJlIGZyb20gdGhlIGxpc3QsIHBs
ZWFzZSB2aXNpdApodHRwczovL2xpc3RzLm9wZW5jbXMub3JnL21haWxtYW4vbGlzdGluZm8vb3Bl
bmNtcy1kZXYKCgoK
--===============8253619940584015241==--