首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >org/apache/chemistry/opencmis/client/api/SessionFactory :java.lang.NoClassDefFoundError

org/apache/chemistry/opencmis/client/api/SessionFactory :java.lang.NoClassDefFoundError
EN

Stack Overflow用户
提问于 2016-01-17 15:31:12
回答 2查看 3.9K关注 0票数 9

我在Alfresco社区4.0工作。

我使用cmis来更新Alfresco中的文档。

我已经在Alfresco中注册了一个文档,这是在保存方法之后检索的文档id:b08e8bce-1b88-489e-a357-1e6385f180a1

现在,我想通过其他内容更改该文件的内容。我用了这个方法:

代码语言:javascript
复制
   public void saveVersioning(File file, String filename, String userName, String pwd, String docId)
        throws Exception {


        SessionFactory factory = SessionFactoryImpl.newInstance();
        Map<String, String> parameters = new HashMap<String, String>();

        // User credentials.
        parameters.put(SessionParameter.USER,userName);
        parameters.put(SessionParameter.PASSWORD, pwd);

        // Connection settings.
        parameters.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

        parameters.put(SessionParameter.ATOMPUB_URL, "http://localhost:9080/alfresco/service/cmis"); // URL to your CMIS server.

        // Create session.
        // Alfresco only provides one repository.
        Repository repository = factory.getRepositories(parameters).get(0);

        Session session = repository.createSession();

        System.out.println("Connected to repository:" + session.getRepositoryInfo().getName());
        System.out.println("Repository id:"+session.getRepositoryInfo().getId());

         // Get the contents of the file
        Document doc = (Document) session.getObject(docId);
        ContentStream contentStream = doc.getContentStream(); // returns null if the document has no content
        if (contentStream != null) {


                String mimetype = "text/plain; charset=UTF-8";
                String content = "";

                if (contentStream != null) {
                    filename = contentStream.getFileName();
                    mimetype = contentStream.getMimeType();
                    content = getContentAsString(contentStream);
                    System.out.println("file name "+filename);
                    System.out.println("minetype "+mimetype);
                    System.out.println("content "+content);
                }



                String updatedContents = content + "\nLine added in new version";

                byte[] buf = updatedContents.getBytes("UTF-8");
                ByteArrayInputStream input = new ByteArrayInputStream(buf);


                contentStream = session.getObjectFactory().createContentStream(
                        filename, buf.length, mimetype, input);



                System.out.println("Document version history");
                {
                    List<Document> versions = doc.getAllVersions();
                    for (Document version : versions) {
                        System.out.println("\tname: " + version.getName());
                        System.out.println("\tversion label: " + version.getVersionLabel());
                        System.out.println("\tversion series id: " + version.getVersionSeriesId());
                        System.out.println("\tchecked out by: "
                                + version.getVersionSeriesCheckedOutBy());
                        System.out.println("\tchecked out id: "
                                + version.getVersionSeriesCheckedOutId());
                        System.out.println("\tmajor version: " + version.isMajorVersion());
                        System.out.println("\tlatest version: " + version.isLatestVersion());
                        System.out.println("\tlatest major version: " + version.isLatestMajorVersion());
                        System.out.println("\tcheckin comment: " + version.getCheckinComment());
                        System.out.println("\tcontent length: " + version.getContentStreamLength()
                                + "\n");
                    }
                }
            }



    }

我使用以下代码调用此方法:

代码语言:javascript
复制
  File file = new File("C:/test.pdf");
       saveVersioning(file, "test.pdf", "admin","admin","b08e8bce-1b88-489e-a357-1e6385f180a1");

我在java项目中使用了这个jar:

所有的jars都被添加到类路径中,但是当我测试我的应用程序时,我得到了以下错误:

代码语言:javascript
复制
Caused by: java.lang.NoClassDefFoundError: org/apache/chemistry/opencmis/client/api/SessionFactory

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:107)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    at com.sun.proxy.$Proxy24.sendTransfer(Unknown Source)
    at 
    ... 111 more
Caused by: java.lang.ClassNotFoundException: org.apache.chemistry.opencmis.client.api.SessionFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1233)
    ... 124 more

我的Al新鲜coCommunity4服务器包含这个jar:

更新了

我发现在Alfresco社区4.0.0

我应该使用化学开放客户端0.6.0

此外,我还应该在代码中使用这个URL:http://localhost:9080/alfresco/cmisatom

我尝试使用以下代码与cmis进行会话,但没有成功:

代码语言:javascript
复制
Map<String, String> parameter = new HashMap<String, String>();

// user credentials
        parameter.put(SessionParameter.USER, "admin");
        parameter.put(SessionParameter.PASSWORD, "admin");

        // connection settings
    parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:9080/alfresco/cmisatom");

    parameter.put(SessionParameter.BINDING_TYPE, BindingType.ATOMPUB.value());

    // create session
    SessionFactory factory = SessionFactoryImpl.newInstance();
        Session session = factory.getRepositories(parameter).get(0).createSession();

就像我说的,我用了这个罐子:

我从chemistry-opencmis-client-impl-0.6.0-with-dependencies.tar.gz下载了所有lib,我还下载了这个jar、0.2.jar

当我测试时,我也有同样的错误。

我在代码中添加了这一行:

代码语言:javascript
复制
parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl");

我认为问题与缺少jar版本有关,而与我的java代码无关,但我试图更改,但没有成功。

代码语言:javascript
复制
parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:9080/alfresco/cmisatom");

有:

代码语言:javascript
复制
parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:9080/alfresco/service/cmis");
EN

回答 2

Stack Overflow用户

发布于 2016-05-09 07:58:17

我不确定这是否是正确的答案,但希望你会发现错误和一些提示。

  1. 首先下载最新的CMIS工作台或下载0.6.0版本
  2. 使用工作台连接到Al新鲜to以检查是否一切正常,例如创建/读取/更新/删除
  3. 读了很多关于CMIS、这里和许多其他的文章。
  4. 当你读到的时候,你会希望你在一个更高版本的Alfresco比4.0。如果您需要一个稳定的CMIS环境,那么您应该升级到4.2.f甚至更高。
  5. 放弃当前的Java项目,从下载页面下载0.6.0和新的依赖项
  6. 达到可以“实际”读取和保存文件的程度。
  7. 在当前的设置中,不可能将文件保存在Alfresco上,无法获取NoClassDefFoundError和更新时获取错误。要么您总是在构建时得到错误,要么您得到了另一个错误。
  8. 将sessionFactory和创建会话代码移动到公共init()或setupConnection()方法,这样您就不会有重复的代码,从而有更多的机会出错
票数 2
EN

Stack Overflow用户

发布于 2016-05-12 08:58:18

我假设您使用另一个类路径运行测试,然后显示在屏幕截图中。

代码语言:javascript
复制
Caused by: java.lang.ClassNotFoundException: org.apache.chemistry.opencmis.client.api.SessionFactory
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387)

你在tomcat容器里做测试吗?在开始测试时仔细检查类路径。如果类路径确实有cmis依赖项,那么检查cmis客户端版本冲突。所有冲突版本都可以由maven (例如)轻松地解决。我建议将项目创建为maven项目,以消除此问题。此外,在运行测试时,maven将在类路径中包含所有cmis依赖项。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34840086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档