Apache Jackrabbit demo(java内容存储例子)

项目中要用到Apache Jackrabbit 这个内容存储开源东西,网上中文的知识真少,昨天看了一下午的API,终于有所了解了,写了一个demo,废话不说,上代码,附加jar包下载地址。直接运行即可

http://download.csdn.net/source/1468982

import javax.jcr.Node; import javax.jcr.Repository; import javax.jcr.Session; import javax.jcr.SimpleCredentials; import org.apache.jackrabbit.core.TransientRepository; /** * jackRabbit 例子 * @author 李晗 */ public class Test { /** * * @param args command line arguments (ignored) * @throws Exception if an error occurs */ public static void main(String[] args) throws Exception { Repository repository = new TransientRepository(); Session session = repository.login(new SimpleCredentials("lihan", "password".toCharArray())); try { String user = session.getUserID(); String name = repository.getDescriptor(Repository.REP_NAME_DESC); System.out.println( "Logged in as " + user + " to a " + name + " repository."); //================================================ Node root = session.getRootNode(); Node hello = root.addNode("hello"); Node world = hello.addNode("world"); world.setProperty("lihan", "true"); session.save(); Node node = root.getNode("hello/world"); System.out.println("index:"+node.getIndex()); System.out.println("name:"+node.getName()); System.out.println("path:"+node.getPath()); System.out.println("ancestor:"+node.getAncestor(0)); } finally { session.logout(); } } }

当然这只是最简单的..继续研究去了。。

你可能感兴趣的:(Apache Jackrabbit demo(java内容存储例子))