Re: How to package java classes in an opencms module

Michael Emmerich via opencms-dev <[email protected]> Tue, 12 Aug 2025 14:56:34 +0200
Newsgroups gmane.comp.cms.opencms.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============4147425120034783837==
Content-Type: multipart/alternative;
 boundary="------------sYw8T47B9AagFSZL5saq9etV"
Content-Language: en-US

This is a multi-part message in MIME format.
--------------sYw8T47B9AagFSZL5saq9etV
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Hello Laurent,

the <resources> node in the manifest file tells the system which files 
or folders should be exported when the module is exported in OpenCms

All exported resources of a module can be found as individual <file> 
sub-nodes in the <files> node. In those nodes, all resource metadata, 
like type, date and user created, path, permissions, properties are stored.

Only those resources that are listed in those <file> nodes are imported 
when you import a module using this manifest file.


The easiest to do would be:

- Create a new module inside of OpenCms. During Module creation you can 
select which folders inside the /system/modules/[your-module-name]/ 
should be created. By default, your module folder is part of the module 
(and everything inside of it).

- Then upload your .jar and .class files in the corresponding /lib and 
/classes folder of your module. Make sure that you have set the export 
points for the /lib and /classes folder in the module configuration

- Export the module from OpenCms and download it. Not extract it and 
take a look at he manifest file to see what is in there.

The format of those <file> nodes is the same that is used in the 
manifest files of a database export in OpenCms.


Kind regards,

Michael


Am 08.08.25 um 15:27 schrieb laurent.druart via opencms-dev:
> 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’s why I implemented
>
> LibraryInitializerextends A_CmsModuleActionimplements I_CmsEventListener
>
> In a previous test I had a section « resources » like this
>
>         <resources>
>             <resource uri="/system/modules/com.opencms.library/"/>
>         </resources>
>
> but not working at all.
>
> So I’ve 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ût 2025 à 14:30, Michael Emmerich via opencms-dev 
>> <[email protected]> a écrit :
>>
>> Laurent,
>>
>> 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.
>>
>> 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.
>>
>>
>> Kind regards,
>>
>> Michael
>>
>>
>>
>> Am 08.08.25 um 11:22 schrieb laurent.druart via opencms-dev:
>>> Hello,
>>>
>>> In add-on to my previous e-mail, here is the content/structure of my 
>>> zip files :
>>>
>>>
>>> And the content of my manifest.xml :
>>>
>>> <?xml version="1.0" encoding="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>
>>>
>>>     <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ès aux données 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>
>>>
>>>         <dependencies/>
>>>
>>>         <exportpoints>
>>>             <exportpoint 
>>> uri="/system/modules/com.opencms.library/classes/" 
>>> destination="WEB-INF/classes/"/>
>>>             <exportpoint 
>>> uri="/system/modules/com.opencms.library/lib/" 
>>> destination="WEB-INF/lib/"/>
>>>         </exportpoints>
>>>         <resources/>
>>>         <parameters>
>>>             <param name="spring.auto.init">true</param>
>>>         </parameters>
>>>     </module>
>>>
>>>     <files/>
>>> </export>
>>>
>>> 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 « com.opencms.library » entries in 
>>> /system/modules
>>>
>>> Thanks for your help.
>>>
>>> Regards,
>>>
>>> Laurent
>>>
>>>> Le 7 août 2025 à 16:41, laurent.druart via opencms-dev 
>>>> <[email protected]> a écrit :
>>>>
>>>> Hello,
>>>>
>>>> I’m 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:
>>>>
>>>> SpringBeanUtils :
>>>>
>>>> public class SpringBeanUtils {
>>>>
>>>>    private static final Log LOG = CmsLog.getLog(SpringBeanUtils.class);
>>>>
>>>>    /**
>>>>     * Récupère le service utilisateur
>>>>     * Exemple d'utilisation dans une page JSP :
>>>>     * <%
>>>>     *   UserService userService = SpringBeanUtils.getUserService();
>>>>     *   List<User> users = userService.getAllActiveUsers();
>>>>     * %>
>>>>     */
>>>>    public static UserService getUserService() {
>>>>        try {
>>>>            return LibraryInitializer.getBean(UserService.class);
>>>>        } catch (Exception e) {
>>>>            LOG.error("Erreur lors de la récupération du 
>>>> UserService", e);
>>>>            throw new RuntimeException("Service utilisateur non 
>>>> disponible", e);
>>>>        }
>>>>    }
>>>>
>>>>    /**
>>>>     * Méthode générique pour récupérer n'importe quel service
>>>>     * Exemple :
>>>>     * MyService service = 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écupération du service: " 
>>>> + serviceClass.getSimpleName(), e);
>>>>            throw new RuntimeException("Service non disponible: " + 
>>>> serviceClass.getSimpleName(), e);
>>>>        }
>>>>    }
>>>>
>>>>    /**
>>>>     * Récupère un bean par son nom
>>>>     * Exemple :
>>>>     * Object bean = SpringBeanUtils.getBean("userService");
>>>>     */
>>>>    public static Object getBean(String beanName) {
>>>>        try {
>>>>            return LibraryInitializer.getBean(beanName);
>>>>        } catch (Exception e) {
>>>>            LOG.error("Erreur lors de la récupération du bean: " + 
>>>> beanName, e);
>>>>            throw new RuntimeException("Bean non disponible: " + 
>>>> beanName, e);
>>>>        }
>>>>    }
>>>>
>>>>    /**
>>>>     * Vérifie si le contexte Spring est disponible
>>>>     */
>>>>    public static boolean isAvailable() {
>>>>        return LibraryInitializer.isSpringContextAvailable();
>>>>    }
>>>>
>>>>    /**
>>>>     * Méthode utilitaire pour vérifier la disponibilité avant 
>>>> utilisation
>>>>     */
>>>>    public static void ensureAvailable() {
>>>>        if (!isAvailable()) {
>>>>            throw new IllegalStateException(
>>>>                    "Le contexte Spring n'est pas disponible. " +
>>>>                            "Vérifiez que le module est correctement 
>>>> initialisé."
>>>>            );
>>>>        }
>>>>    }
>>>> }
>>>>
>>>> with static method getUserService() I can call the userService 
>>>> bean. No problem with it.
>>>>
>>>> And second class LibraryInitializer wich must initialise the spring 
>>>> context and configure it:
>>>>
>>>> public class LibraryInitializer extends A_CmsModuleAction 
>>>> implements I_CmsEventListener {
>>>>
>>>>    private static final String MODULE_NAME = "opencms-spring-library";
>>>>    private static ApplicationContext springContext;
>>>>    private static final org.apache.commons.logging.Log LOG = 
>>>> CmsLog.getLog(LibraryInitializer.class);
>>>>
>>>>    /**
>>>>     * Initialisation du module
>>>>     */
>>>>    @Override
>>>>    public void initialize(org.opencms.file.CmsObject adminCms,
>>>>                           org.opencms.configuration.CmsConfigurationManager 
>>>> configurationManager,
>>>>                           CmsModule module) {
>>>>
>>>>        LOG.info("Initialisation de la librairie Spring classique 
>>>> pour OpenCMS");
>>>>
>>>>        try {
>>>>            // Configuration des propriétés système
>>>>            configureSystemProperties();
>>>>
>>>>            // Création du contexte Spring CLASSIQUE
>>>>            AnnotationConfigApplicationContext context = new 
>>>> AnnotationConfigApplicationContext();
>>>>            context.register(com.opencms.library.config.LibraryConfiguration.class);
>>>>            context.refresh();
>>>>
>>>>            springContext = context;
>>>>
>>>>            // Enregistrement des listeners OpenCMS
>>>>            OpenCms.addCmsEventListener(this);
>>>>
>>>>            LOG.info("Librairie Spring classique initialisée avec 
>>>> succès");
>>>>
>>>>        } 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);
>>>>        }
>>>>    }
>>>>
>>>>    /**
>>>>     * Arrêt du module
>>>>     */
>>>>    @Override
>>>>    public void shutDown(CmsModule module) {
>>>>        LOG.info("Arrêt de la librairie Spring classique");
>>>>
>>>>        if (springContext != null) {
>>>>            try {
>>>>                if (springContext instanceof 
>>>> AnnotationConfigApplicationContext) {
>>>>                    ((AnnotationConfigApplicationContext) 
>>>> springContext).close();
>>>>                }
>>>>                LOG.info("Contexte Spring fermé avec succès");
>>>>            } catch (Exception e) {
>>>>                LOG.error("Erreur lors de l'arrêt du contexte 
>>>> Spring", e);
>>>>            } finally {
>>>>                springContext = null;
>>>>            }
>>>>        }
>>>>    }
>>>>
>>>>    /**
>>>>     * Gestion des événements OpenCMS
>>>>     */
>>>>    @Override
>>>>    public void cmsEvent(CmsEvent event) {
>>>>        switch (event.getType()) {
>>>>            case I_CmsEventListener.EVENT_PUBLISH_PROJECT:
>>>>                LOG.debug("Événement de publication détecté");
>>>>                break;
>>>>            case I_CmsEventListener.EVENT_CLEAR_CACHES:
>>>>                LOG.debug("Événement de nettoyage des caches détecté");
>>>>                break;
>>>>        }
>>>>    }
>>>>
>>>>    /**
>>>>     * Configuration des propriétés système
>>>>     */
>>>>    private void configureSystemProperties() {
>>>>        // Configuration de base de données (valeurs par défaut)
>>>>        if (System.getProperty("spring.datasource.url") == null) {
>>>>            System.setProperty("spring.datasource.url", 
>>>> "jdbc:postgresql://postgres-db:5432/libdb");
>>>>        }
>>>>        if (System.getProperty("spring.datasource.username") == null) {
>>>>            System.setProperty("spring.datasource.username", "appuser");
>>>>        }
>>>>        if (System.getProperty("spring.datasource.password") == null) {
>>>>            System.setProperty("spring.datasource.password", 
>>>> "apppassword");
>>>>        }
>>>>
>>>>        LOG.info("Propriétés système configurées");
>>>>    }
>>>>
>>>>    /**
>>>>     * Accès aux beans Spring
>>>>     */
>>>>    public static <T> T getBean(Class<T> beanClass) {
>>>>        if (springContext == null) {
>>>>            throw new IllegalStateException("Le contexte Spring 
>>>> n'est pas initialisé");
>>>>        }
>>>>        return springContext.getBean(beanClass);
>>>>    }
>>>>
>>>>    public static Object getBean(String beanName) {
>>>>        if (springContext == null) {
>>>>            throw new IllegalStateException("Le contexte Spring 
>>>> n'est pas initialisé");
>>>>        }
>>>>        return springContext.getBean(beanName);
>>>>    }
>>>>
>>>>    public static boolean isSpringContextAvailable() {
>>>>        return springContext != null;
>>>>    }
>>>> }
>>>>
>>>> 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:
>>>>
>>>>           com.opencms.library.integration.LibraryInitializer 
>>>> initializer =
>>>>                new 
>>>> com.opencms.library.integration.LibraryInitializer();
>>>>
>>>>            // Appel direct de initialize avec des paramètres nulls 
>>>> (notre version simplifiée les gère)
>>>>            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.
>>>>
>>>> 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.
>>>>
>>>> Can you help me?
>>>> Does it exist a tutorial or how-to?
>>>>
>>>> Am i wrong with public class LibraryInitializer extends 
>>>> A_CmsModuleAction implements I_CmsEventListener ?
>>>>
>>>> Thank you
>>>>
>>>> Kind regards,
>>>>
>>>> Laurent
>>>>
>>>>
>>>> _______________________________________________
>>>> 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
>>>>
>>>>
>>>>
>>>
>>> _______________________________________________
>>> 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
>>>
>>>
>>>
>> -- 
>> Michael Emmerich
>> Alkacon Software GmbH & Co. KG - The OpenCms Experts
>> http://www.alkacon.com
>> http://www.opencms.org
>>
>> _______________________________________________
>> 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
>>
>>
>>
>
>
> _______________________________________________
> 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
>
>
>
-- 
Michael Emmerich
  
-------------------

Alkacon Software GmbH & Co. KG - The OpenCms Experts
Michael Emmerich
An der Wachsfabrik 13
50996 Koeln, DE
  
Tel: +49 (0)2236 3826-14
Fax: +49 (0)2236 3826-20
Email:[email protected]

http://www.alkacon.com
http://www.opencms.org

Amtsgericht Köln, HRA 32185, USt-IdNr.: DE259882372
Vertreten durch: Alkacon Verwaltungs GmbH
Geschäftsführer: Alexander Kandzior, Amtsgericht Köln, HRB 88218

--------------sYw8T47B9AagFSZL5saq9etV
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p>Hello Laurent,</p>
    <p>the &lt;resources&gt; node in the manifest file tells the system
      which files or folders should be exported when the module is
      exported in OpenCms</p>
    <p>All exported resources of a module can be found as individual
      &lt;file&gt; sub-nodes in the &lt;files&gt; node. In those nodes,
      all resource metadata, like type, date and user created, path,
      permissions, properties are stored.</p>
    <p>Only those resources that are listed in those &lt;file&gt; nodes
      are imported when you import a module using this manifest file.</p>
    <p><br>
    </p>
    <p>The easiest to do would be:</p>
    <p>- Create a new module inside of OpenCms. During Module creation
      you can select which folders inside the
      /system/modules/[your-module-name]/ should be created. By default,
      your module folder is part of the module (and everything inside of
      it).</p>
    <p>- Then upload your .jar and .class files in the corresponding
      /lib and /classes folder of your module. Make sure that you have
      set the export points for the /lib and /classes folder in the
      module configuration</p>
    <p>- Export the module from OpenCms and download it. Not extract it
      and take a look at he manifest file to see what is in there.</p>
    <p>The format of those &lt;file&gt; nodes is the same that is used
      in the manifest files of a database export in OpenCms.</p>
    <p><br>
    </p>
    <p>Kind regards,</p>
    <p>Michael</p>
    <p><br>
    </p>
    <div class="moz-cite-prefix">Am 08.08.25 um 15:27 schrieb
      laurent.druart via opencms-dev:<br>
    </div>
    <blockquote type="cite"
      cite="mid:[email protected]">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      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’s why I implemented </div>
      <div><br>
      </div>
      <div>
        <pre
style="background-color: rgb(43, 43, 43); color: rgb(169, 183, 198); font-family: &quot;JetBrains Mono&quot;, monospace;">LibraryInitializer <span
        style="color: rgb(204, 120, 50);">extends </span>A_CmsModuleAction <span
        style="color: rgb(204, 120, 50);">implements </span>I_CmsEventListener</pre>
      </div>
      <div><br>
      </div>
      <div>In a previous test I had a section « resources » like this</div>
      <div><br>
      </div>
      <div>
        <div>        &lt;resources&gt;</div>
        <div>            &lt;resource
          uri="/system/modules/com.opencms.library/"/&gt;</div>
        <div>        &lt;/resources&gt;</div>
        <div><br>
        </div>
        <div>but not working at all.</div>
        <div><br>
        </div>
        <div>So I’ve 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="cite">
            <div>Le 8 août 2025 à 14:30, Michael Emmerich via
              opencms-dev <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]">&lt;[email protected]&gt;</a> a écrit :</div>
            <br class="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="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>
                  &lt;?xml version="1.0" encoding="UTF-8"?&gt;<br>
                  &lt;export&gt;<br>
                      &lt;info&gt;<br>
                          &lt;creator&gt;OpenCMS Module
                  Builder&lt;/creator&gt;<br>
        &lt;opencms_version&gt;19.0&lt;/opencms_version&gt;<br>
                          &lt;createdate&gt;Wed, 07 Aug 2025 10:00:00
                  GMT&lt;/createdate&gt;<br>
                          &lt;project&gt;Offline&lt;/project&gt;<br>
                          &lt;export_version&gt;7&lt;/export_version&gt;<br>
                      &lt;/info&gt;<br>
                  <br>
                      &lt;module&gt;<br>
                          &lt;name&gt;com.opencms.library&lt;/name&gt;<br>
                          &lt;nicename&gt;OpenCMS Spring Data JDBC
                  Library&lt;/nicename&gt;<br>
                          &lt;group&gt;Custom Libraries&lt;/group&gt;<br>
        &lt;class&gt;com.opencms.library.integration.LibraryInitializer&lt;/class&gt;<br>
                          &lt;description&gt;Librairie Spring classique
                  pour OpenCMS avec accès aux données
                  PostgreSQL&lt;/description&gt;<br>
                          &lt;version&gt;1.0.0&lt;/version&gt;<br>
                          &lt;authorname&gt;Laurent
                  Druart&lt;/authorname&gt;<br>
        &lt;authoremail&gt;<a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>&lt;/authoremail&gt;<br>
                          &lt;datecreated&gt;Wed, 07 Aug 2025 10:00:00
                  GMT&lt;/datecreated&gt;<br>
        &lt;userinstalled&gt;Admin&lt;/userinstalled&gt;<br>
                          &lt;dateinstalled&gt;Wed, 07 Aug 2025 10:00:00
                  GMT&lt;/dateinstalled&gt;<br>
                  <br>
                          &lt;dependencies/&gt;<br>
                  <br>
                          &lt;exportpoints&gt;<br>
                              &lt;exportpoint
                  uri="/system/modules/com.opencms.library/classes/"
                  destination="WEB-INF/classes/"/&gt;<br>
                              &lt;exportpoint
                  uri="/system/modules/com.opencms.library/lib/"
                  destination="WEB-INF/lib/"/&gt;<br>
                          &lt;/exportpoints&gt;<br>
                          &lt;resources/&gt;<br>
                          &lt;parameters&gt;<br>
                              &lt;param
                  name="spring.auto.init"&gt;true&lt;/param&gt;<br>
                          &lt;/parameters&gt;<br>
                      &lt;/module&gt;<br>
                  <br>
                      &lt;files/&gt;<br>
                  &lt;/export&gt;<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 «
                  com.opencms.library » entries in /system/modules<br>
                  <br>
                  Thanks for your help.<br>
                  <br>
                  Regards,<br>
                  <br>
                  Laurent<br>
                  <br>
                  <blockquote type="cite">Le 7 août 2025 à 16:41,
                    laurent.druart via opencms-dev
                    <a class="moz-txt-link-rfc2396E" href="mailto:[email protected]">&lt;[email protected]&gt;</a> a écrit :<br>
                    <br>
                    Hello,<br>
                    <br>
                    I’m 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 =
                    CmsLog.getLog(SpringBeanUtils.class);<br>
                    <br>
                       /**<br>
                        * Récupère le service utilisateur<br>
                        * Exemple d'utilisation dans une page JSP :<br>
                        * &lt;%<br>
                        *   UserService userService =
                    SpringBeanUtils.getUserService();<br>
                        *   List&lt;User&gt; users =
                    userService.getAllActiveUsers();<br>
                        * %&gt;<br>
                        */<br>
                       public static UserService getUserService() {<br>
                           try {<br>
                               return
                    LibraryInitializer.getBean(UserService.class);<br>
                           } catch (Exception e) {<br>
                               LOG.error("Erreur lors de la récupération
                    du UserService", e);<br>
                               throw new RuntimeException("Service
                    utilisateur non disponible", e);<br>
                           }<br>
                       }<br>
                    <br>
                       /**<br>
                        * Méthode générique pour récupérer n'importe
                    quel service<br>
                        * Exemple :<br>
                        * MyService service =
                    SpringBeanUtils.getService(MyService.class);<br>
                        */<br>
                       public static &lt;T&gt; T
                    getService(Class&lt;T&gt; serviceClass) {<br>
                           try {<br>
                               return
                    LibraryInitializer.getBean(serviceClass);<br>
                           } catch (Exception e) {<br>
                               LOG.error("Erreur lors de la récupération
                    du service: " + serviceClass.getSimpleName(), e);<br>
                               throw new RuntimeException("Service non
                    disponible: " + serviceClass.getSimpleName(), e);<br>
                           }<br>
                       }<br>
                    <br>
                       /**<br>
                        * Récupère un bean par son nom<br>
                        * Exemple :<br>
                        * Object bean =
                    SpringBeanUtils.getBean("userService");<br>
                        */<br>
                       public static Object getBean(String beanName) {<br>
                           try {<br>
                               return
                    LibraryInitializer.getBean(beanName);<br>
                           } catch (Exception e) {<br>
                               LOG.error("Erreur lors de la récupération
                    du bean: " + beanName, e);<br>
                               throw new RuntimeException("Bean non
                    disponible: " + beanName, e);<br>
                           }<br>
                       }<br>
                    <br>
                       /**<br>
                        * Vérifie si le contexte Spring est disponible<br>
                        */<br>
                       public static boolean isAvailable() {<br>
                           return
                    LibraryInitializer.isSpringContextAvailable();<br>
                       }<br>
                    <br>
                       /**<br>
                        * Méthode utilitaire pour vérifier la
                    disponibilité avant utilisation<br>
                        */<br>
                       public static void ensureAvailable() {<br>
                           if (!isAvailable()) {<br>
                               throw new IllegalStateException(<br>
                                       "Le contexte Spring n'est pas
                    disponible. " +<br>
                                               "Vérifiez que le module
                    est correctement initialisé."<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 =
                    "opencms-spring-library";<br>
                       private static ApplicationContext springContext;<br>
                       private static final
                    org.apache.commons.logging.Log LOG =
                    CmsLog.getLog(LibraryInitializer.class);<br>
                    <br>
                       /**<br>
                        * Initialisation du module<br>
                        */<br>
                       @Override<br>
                       public void initialize(org.opencms.file.CmsObject
                    adminCms,<br>
                          org.opencms.configuration.CmsConfigurationManager
                    configurationManager,<br>
                                              CmsModule module) {<br>
                    <br>
                           LOG.info("Initialisation de la librairie
                    Spring classique pour OpenCMS");<br>
                    <br>
                           try {<br>
                               // Configuration des propriétés système<br>
                               configureSystemProperties();<br>
                    <br>
                               // Création du contexte Spring CLASSIQUE<br>
                               AnnotationConfigApplicationContext
                    context = new AnnotationConfigApplicationContext();<br>
           context.register(com.opencms.library.config.LibraryConfiguration.class);<br>
                               context.refresh();<br>
                    <br>
                               springContext = context;<br>
                    <br>
                               // Enregistrement des listeners OpenCMS<br>
                               OpenCms.addCmsEventListener(this);<br>
                    <br>
                               LOG.info("Librairie Spring classique
                    initialisée avec succès");<br>
                    <br>
                           } catch (Exception e) {<br>
                               LOG.error("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êt du module<br>
                        */<br>
                       @Override<br>
                       public void shutDown(CmsModule module) {<br>
                           LOG.info("Arrêt de la librairie Spring
                    classique");<br>
                    <br>
                           if (springContext != null) {<br>
                               try {<br>
                                   if (springContext instanceof
                    AnnotationConfigApplicationContext) {<br>
                   ((AnnotationConfigApplicationContext)
                    springContext).close();<br>
                                   }<br>
                                   LOG.info("Contexte Spring fermé avec
                    succès");<br>
                               } catch (Exception e) {<br>
                                   LOG.error("Erreur lors de l'arrêt du
                    contexte Spring", e);<br>
                               } finally {<br>
                                   springContext = null;<br>
                               }<br>
                           }<br>
                       }<br>
                    <br>
                       /**<br>
                        * Gestion des événements OpenCMS<br>
                        */<br>
                       @Override<br>
                       public void cmsEvent(CmsEvent event) {<br>
                           switch (event.getType()) {<br>
                               case
                    I_CmsEventListener.EVENT_PUBLISH_PROJECT:<br>
                                   LOG.debug("Événement de publication
                    détecté");<br>
                                   break;<br>
                               case
                    I_CmsEventListener.EVENT_CLEAR_CACHES:<br>
                                   LOG.debug("Événement de nettoyage des
                    caches détecté");<br>
                                   break;<br>
                           }<br>
                       }<br>
                    <br>
                       /**<br>
                        * Configuration des propriétés système<br>
                        */<br>
                       private void configureSystemProperties() {<br>
                           // Configuration de base de données (valeurs
                    par défaut)<br>
                           if
                    (System.getProperty("spring.datasource.url") ==
                    null) {<br>
           System.setProperty("spring.datasource.url",
                    "jdbc:postgresql://postgres-db:5432/libdb");<br>
                           }<br>
                           if
                    (System.getProperty("spring.datasource.username") ==
                    null) {<br>
           System.setProperty("spring.datasource.username", "appuser");<br>
                           }<br>
                           if
                    (System.getProperty("spring.datasource.password") ==
                    null) {<br>
           System.setProperty("spring.datasource.password",
                    "apppassword");<br>
                           }<br>
                    <br>
                           LOG.info("Propriétés système configurées");<br>
                       }<br>
                    <br>
                       /**<br>
                        * Accès aux beans Spring<br>
                        */<br>
                       public static &lt;T&gt; T getBean(Class&lt;T&gt;
                    beanClass) {<br>
                           if (springContext == null) {<br>
                               throw new IllegalStateException("Le
                    contexte Spring n'est pas initialisé");<br>
                           }<br>
                           return springContext.getBean(beanClass);<br>
                       }<br>
                    <br>
                       public static Object getBean(String beanName) {<br>
                           if (springContext == null) {<br>
                               throw new IllegalStateException("Le
                    contexte Spring n'est pas initialisé");<br>
                           }<br>
                           return springContext.getBean(beanName);<br>
                       }<br>
                    <br>
                       public static boolean isSpringContextAvailable()
                    {<br>
                           return springContext != 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.library.integration.LibraryInitializer initializer
                    =<br>
                                   new
                    com.opencms.library.integration.LibraryInitializer();<br>
                    <br>
                               // Appel direct de initialize avec des
                    paramètres nulls (notre version simplifiée les gère)<br>
                               initializer.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>
<a class="moz-txt-link-freetext" href="https://lists.opencms.org/mailman/listinfo/opencms-dev">https://lists.opencms.org/mailman/listinfo/opencms-dev</a><br>
                    <br>
                    <br>
                    <br>
                  </blockquote>
                  <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>
                  <a class="moz-txt-link-freetext" href="https://lists.opencms.org/mailman/listinfo/opencms-dev">https://lists.opencms.org/mailman/listinfo/opencms-dev</a><br>
                  <br>
                  <br>
                  <br>
                </blockquote>
                -- <br>
                Michael Emmerich<br>
                Alkacon Software GmbH &amp; Co. KG - The OpenCms Experts<br>
                <a class="moz-txt-link-freetext" href="http://www.alkacon.com">http://www.alkacon.com</a><br>
                <a class="moz-txt-link-freetext" href="http://www.opencms.org">http://www.opencms.org</a><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>
                <a class="moz-txt-link-freetext" href="https://lists.opencms.org/mailman/listinfo/opencms-dev">https://lists.opencms.org/mailman/listinfo/opencms-dev</a><br>
                <br>
                <br>
                <br>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="moz-mime-attachment-header"></fieldset>
      <pre wrap="" class="moz-quote-pre">_______________________________________________
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
<a class="moz-txt-link-freetext" href="https://lists.opencms.org/mailman/listinfo/opencms-dev">https://lists.opencms.org/mailman/listinfo/opencms-dev</a>



</pre>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Michael Emmerich
 
-------------------

Alkacon Software GmbH &amp; Co. KG - The OpenCms Experts
Michael Emmerich
An der Wachsfabrik 13
50996 Koeln, DE
 
Tel: +49 (0)2236 3826-14
Fax: +49 (0)2236 3826-20
Email: <a class="moz-txt-link-abbreviated" href="mailto:[email protected]">[email protected]</a>

<a class="moz-txt-link-freetext" href="http://www.alkacon.com">http://www.alkacon.com</a>
<a class="moz-txt-link-freetext" href="http://www.opencms.org">http://www.opencms.org</a>

Amtsgericht Köln, HRA 32185, USt-IdNr.: DE259882372
Vertreten durch: Alkacon Verwaltungs GmbH
Geschäftsführer: Alexander Kandzior, Amtsgericht Köln, HRB 88218</pre>
  </body>
</html>

--------------sYw8T47B9AagFSZL5saq9etV--


--===============4147425120034783837==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVGhpcyBtYWls
IGlzIHNlbnQgdG8geW91IGZyb20gdGhlIG9wZW5jbXMtZGV2IG1haWxpbmcgbGlzdApUbyBjaGFu
Z2UgeW91ciBsaXN0IG9wdGlvbnMsIG9yIHRvIHVuc3Vic2NyaWJlIGZyb20gdGhlIGxpc3QsIHBs
ZWFzZSB2aXNpdApodHRwczovL2xpc3RzLm9wZW5jbXMub3JnL21haWxtYW4vbGlzdGluZm8vb3Bl
bmNtcy1kZXYKCgoK

--===============4147425120034783837==--