OK, I finally realized I needed jackrabbit-api.jar on the class path.
JackRabbitNodeTypeManager now resolves and compiles. But at runtime I get:
java.lang.ClassCastException:
org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl cannot be cast to
org.apache.jackrabbit.api.JackrabbitNodeTypeManager. JackRabbitNodeTypeManager
is also deprecated. I read a thread where CND imports can be done with spi
commons and suggesting to deprecate the fore mentioned method. Is that what I
should be using for NodeType management. Anyone have an example for that?
package com.ist.jcr.jackrabbit.test;
import java.io.FileInputStream;
import javax.jcr.LoginException;
import javax.jcr.Repository;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.SimpleCredentials;
import javax.jcr.nodetype.NoSuchNodeTypeException;
import javax.jcr.nodetype.NodeType;
import org.apache.jackrabbit.api.JackrabbitNodeTypeManager;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
public class NodeManagerTest {
private static Logger log = Logger.getLogger(NodeManagerTest.class);
public NodeManagerTest() {
Repository repository = JackrabbitInterfaceHelper.getRepository();
Session session = null;
try {
session = repository.login(new
SimpleCredentials("username", "password".toCharArray()));
} catch (LoginException e) {
e.printStackTrace();
} catch (RepositoryException e) {
e.printStackTrace();
}
try {
((JackrabbitNodeTypeManager)
session.getWorkspace().getNodeTypeManager()).registerNodeTypes(new
FileInputStream("./resources/nodetypes_test1.xml"),
JackrabbitNodeTypeManager.TEXT_XML);
}
catch (Exception e)
{
e.printStackTrace();
}
NodeType test1 = null;
try {
test1 =
session.getWorkspace().getNodeTypeManager().getNodeType("ocm:test1");
} catch (NoSuchNodeTypeException e) {
e.printStackTrace();
} catch (RepositoryException e) {
e.printStackTrace();
}
if (test1 == null)
{
System.err.println("Null NodeType: ocm:test1");
}
}
public static void main(String[] args) {
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.DEBUG);
Logger.getLogger("org.apache").setLevel(Level.INFO);
Logger.getLogger("httpclient").setLevel(Level.INFO);
NodeManagerTest test = new NodeManagerTest();
}
}
Steve
-----Original Message-----
From: Birmingham, Steven [mailto:[email protected]]
Sent: Wednesday, March 03, 2010 4:44 PM
To: [email protected]
Subject: RE: NodeType creation
I built and added jackrabbit-core-2.0.0.jar to the build path, but
JackRabbitNodeTypeManager is still unresolved. Yes, I was trying to do an
evaluation on the standalone server. So, are you saying NodeType management in
2.0 is not available in the standalone server?
I will download the 2.0 war file and see if things work differently on Tomcat.
I am a little confused as there is documentation on the 2.0 website for
NodeType management but I guess it is incomplete?
Thanks for your help,
Steve
-----Original Message-----
From: Stefan Guggisberg [mailto:[email protected]]
Sent: Wednesday, March 03, 2010 1:30 PM
To: [email protected]
Subject: Re: NodeType creation
On 03.03.2010, at 19:01, "Birmingham, Steven"
<[email protected]> wrote:
> Thanks for the response.
>
> JackrabbitNodeTypeManager is not on the class path either. I have
> all the 2.0 jars on the class path.
> For jackrabbitNodeTypeManagerImpl I get three implementations on the
> classpath:
> //import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl;
> //import
> org.apache.jackrabbit.ocm.nodemanagement.impl.jackrabbit.NodeTypeManagerImpl;
> import
> org.apache.jackrabbit.ocm.nodemanagement.impl.jeceira.NodeTypeManagerImpl;
>
> Does NodeType registration work for you in 2.0?
>
yes
JackrabbitNodeTypeManager is included in jackrabbit-core, which is
missing from your dependencies list.
are you accessing a stand-alone jackrabbit server? if yes, you might
be out of luck since the said method is only available on a local,
i.e. embedded instance.
cheers
stefan
> Here are my dependencies.
>
> <dependency org="org/apache" name="log4j" rev="1.2+"
> conf="compile"/>
> <dependency org="javax.jcr" name="jcr" rev="2.0" conf="compile"/>
> <dependency org="org/apache/jackrabbit" name="jackrabbit-jcr-
> commons" rev="2.0.0" conf="compile"/>
> <dependency org="org/apache/jackrabbit" name="jackrabbit-jcr2dav"
> rev="2.0.0" conf="compile"/>
> <dependency org="org/apache/jackrabbit" name="jackrabbit-jcr2spi"
> rev="2.0.0" conf="compile"/>
> <dependency org="org/apache/jackrabbit" name="jackrabbit-spi"
> rev="2.0.0" conf="compile"/>
> <dependency org="org/apache/jackrabbit" name="jackrabbit-spi2dav"
> rev="2.0.0" conf="compile"/>
> <dependency org="org/apache/jackrabbit" name="jackrabbit-spi-
> commons" rev="2.0.0" conf="compile"/>
> <dependency org="org/apache/jackrabbit" name="jackrabbit-webdav"
> rev="2.0.0" conf="compile"/>
> <dependency org="org/apache/jackrabbit" name="jackrabbit-jcr-
> server" rev="2.0.0" conf="compile"/>
> <dependency org="org/apache" name="commons-httpclient"
> rev="3.0.1" conf="compile"/>
> <dependency org="org/apache" name="commons-codec" rev="1.3"
> conf="compile"/>
> <dependency org="org/apache" name="commons-logging" rev="1.1.1"
> conf="compile"/>
> <dependency org="org/apache" name="commons-collections" rev="3.2"
> conf="compile"/>
> <dependency org="org/slf4j" name="slf4j-api" rev="1.5.2"
> conf="compile"/>
> <dependency org="org/slf4j" name="slf4j-log4j12" rev="1.5.2"
> conf="compile"/>
>
> Steve
>
> -----Original Message-----
> From: Stefan Guggisberg [mailto:[email protected]]
> Sent: Wednesday, March 03, 2010 10:44 AM
> To: [email protected]
> Subject: Re: NodeType creation
>
> On Wed, Mar 3, 2010 at 5:25 PM, Birmingham, Steven
> <[email protected]> wrote:
>> Hello,
>>
>> I am trying to read a NodeType configuration from an xml file. The
>> example I used was from the ocm test classes.
>>
>>
>> jackrabbitNodeTypeManagerImpl.createNodeTypesFromConfiguration
>> (session,
>> new FileInputStream("./resources/
>> Signal.xml"));
>>
>> Exception in thread "main" java.lang.NoClassDefFoundError: org/
>> apache/jackrabbit/core/nodetype/xml/NodeTypeReader
>>
>> I have jcr-2.0.jar and all the other jackrabbit bundles on the
>> class path. Am I somehow missing a jar or is this method not
>> supported anymore or changed?
>
> try this:
> http://jackrabbit.apache.org/api/2.0/org/apache/jackrabbit/api/JackrabbitNodeTypeManager.html#registerNodeTypes(java.io.InputStream,%20java.lang.String)
>
> e.g.
>
> ((JackrabbitNodeTypeManager)
> session.getNodeTypeManager()).registerNodeTypes(new
> FileInputStream("./resources/Signal.xml"),
> JackrabbitNodeTypeManager.TEXT_XML);
>
> cheers
> stefan
>>
>> Thanks,
>> Steve
>>
>> ________________________________
>> This e-mail and any files transmitted with it may be proprietary
>> and are intended solely for the use of the individual or entity to
>> whom they are addressed. If you have received this e-mail in error
>> please notify the sender.
>> Please note that any views or opinions presented in this e-mail are
>> solely those of the author and do not necessarily represent those
>> of ITT Corporation. The recipient should check this e-mail and any
>> attachments for the presence of viruses. ITT accepts no liability
>> for any damage caused by any virus transmitted by this e-mail.
>>