jackrabbit-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Aleksei Lukin <lu...@stu.cn.ua>
Subject Re: accessing JCR over JNDI
Date Fri, 10 Oct 2008 11:59:56 GMT
Friday 10 October 2008 12:57:28 Blanco Emanuele написав:
> Still got null using java:jcr/repo.
>
> I'm now following this link:
> http://th1rty7.blogspot.com/2008/08/jackrabbit-on-jboss-with-jndi-rmi.html
> but I really wonder why it doesn't work.
>
>
>
>
> -----Original Message-----
> From: Cédric Chantepie [mailto:cchantepie@corsaire.fr]
> Sent: venerdì 10 ottobre 2008 11.36
> To: users@jackrabbit.apache.org
> Subject: Re: accessing JCR over JNDI
>
> Blanco Emanuele a écrit :
> > With almost the same code in a WAR deployed in the same jboss makes me
> > repo null.
> >
> > I really have no glue about that.
>
> Try changing your JNDI ref name, maybe java:jcr/local is reserved.
>
Well, first question is: how do you start JCR?  You need model 2 to be able to access JCR
from all deployed apps.
To do so you msut define global JNDI resource  in tomcat's config like this:
  <GlobalNamingResources>
   ......
    <!--
       JackRabbit content repository //
     --> 
    <Resource configFilePath="/usr/local/jackrabbit-repo/repository.xml" 
              factory="org.apache.jackrabbit.core.jndi.BindableRepositoryFactory" 
              name="jcr/globalRepository" repHomeDir="/usr/local/jackrabbit-repo" 
              type="javax.jcr.Repository"
	      auth="Container" />
              
  </GlobalNamingResources>

Thus Tomcat must have all libraries of JCR available. The simpliest way  is  just to put all
of it in ${tomcat_home}/lib

So tomcat will start JCR whet it starts.
Next step is configuration of web application. You must put following reference to global
repo into your context.xml

 <ResourceLink global="jcr/globalRepository" name="jcr/repository" type="javax.jcr.Repository"/>

After that ytou can obtain JNDI access to JCR with following code:

        BindableRepository jrepository = null;

        try {
            InitialContext context = new InitialContext();
            Context environment = (Context) context.lookup("java:comp/env");
            jrepository = (BindableRepository) environment.lookup("/jcr/repository");

...}
 the best place for this code is  
 public void contextInitialized(ServletContextEvent sce) method  of application listener.
Then you can bind repository to web application context and use in any place of your 
application.


-- 
SY, Alex Lukin
RIPE NIC HDL: LEXA1-RIPE

Mime
View raw message