cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing Alfresco JCR: jcr-context.xml and alfresco-jcr.jar

alexeyg
Champ in-the-making
Champ in-the-making
Please tell me how I can access Alfresco from another Context in Tomcat. 

I use:
ApplicationContext context = new ClassPathXmlApplicationContext("classpathSmiley Surprisedrg/alfresco/jcr-context.xml");

and get:

"java.io.FileNotFoundException: class path resource [org/alfresco/jcr-context.xml] cannot be opened because it does not exist"

Steps:

Downloaded and installed Alfresco-Tomcat bundle.

Set up and ran Alfresco.  All is good.

Created another webapp meant to use Alfresco JCR.

According to:
http://www.alfresco.org/mediawiki/index.php/Introducing_the_Alfresco_Java_Content_Repository_API

I did:
ApplicationContext context = new ClassPathXmlApplicationContext("classpathSmiley Surprisedrg/alfresco/jcr-context.xml");
Repository repository = (Repository)context.getBean("JCR.Repository");

Resolved several ClassNotFound exeptions (had to drop jcr JAR into tomcat).

Now I get:

java.io.FileNotFoundException: class path resource [org/alfresco/jcr-context.xml] cannot be opened because it does not exist

Is this happening because Alfresco and myApp are in different Tomcat contexts? 

I searched everywhere for jcr-context.xml and indeed it is nowhere to be found (my app or Alfresco).  Neither is alcresco-jcr.jar.

thank you!
6 REPLIES 6

alexeyg
Champ in-the-making
Champ in-the-making
Strange that there are no replies…  this is an easy question and 1 quick line would help so much.  Oh well, after messing with it for a while here is whay I found.

alfresco-jcr.jar does not get packaged with the Web Client.  It gets built but is never included.  So is jcr-context.xml that was refered from the Wiki.  This is either a change or a bug.  In either case, do not start looking for alfresco-jcr.jar in the alfresco.war.  It is not there.

Wiki has been updated with new access information.
ApplicationContext appContext = new ClassPathXmlApplicationContext("alfresco/application-context.xml");

  ServiceRegistry registry = (ServiceRegistry)appContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
  if (registry.isServiceProvided(ServiceRegistry.NODE_SERVICE)
  {
    NodeService nodeService = registry.getNodeService();
    …

http://www.alfresco.org/mediawiki/index.php/Alfresco_Content_Management_Java_API

davidc
Star Contributor
Star Contributor
You're right, the JCR implementation is not included in the downloadable Alfresco bundle.  In fact, there are several pieces that are not bundled e.g. PHP library, Web Services Client library.  It's a very good point.

We'll look to improve this, either by:

- bundling everything together into the currently available bundle
- providing a seperate "developer" bundle with all appropriate jars and configuration
- providing further seperate downloads

I don't completely understand your WIKI update… the snippet of configuration you've highlighted does not refer to JCR access.

alexeyg
Champ in-the-making
Champ in-the-making
I thought I could get access to the Repository through ServiceRegistry?

Is it possible to have same Repository accessed by Alfresco Web Client and another web app?  That is ultimately the goal.  Does each context in Tomcat require a repository to be started up?  Documentation on non-WebClient access is pretty scarce…  thank you very much!

chi
Champ in-the-making
Champ in-the-making
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

ApplicationContext context = new ClassPathXmlApplicationContext("jcr-context.xml");

any idea guys?
It keeps saying it can't find the xml file

Error


Feb 15, 2006 2:57:27 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [jcr-context.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [jcr-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [jcr-context.xml] cannot be opened because it does not exist
java.io.FileNotFoundException: class path resource [jcr-context.xml] cannot be opened because it does not exist
   at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:137)
   at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:167)
   at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:148)
   at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126)
   at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
   at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
   at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:81)
   at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:89)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:269)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:87)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:72)
   at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:63)
   at com.lexmark.jcr.TestingAlfresco.main(TestingAlfresco.java:50)

davidc
Star Contributor
Star Contributor
jcr-context.xml must live in your classpath.  By default, it's placed into /alfresco, so you should refer to it as "classpath:alfresco/jcr-context.xml".

peterm
Champ in-the-making
Champ in-the-making
Also noticed that the jcr-context.xml will attempt to load alfresco/application-context.xml. If an attempt is made to load jcr-context in the alfresco web app, the app context will try to be loaded twice (once by the web client itself, and again by jcr-context.xml). I needed to remove the import from jcr-context.xml to avoid this.