2016-01-17 15 views
9

Tôi làm việc với Alfresco Community 4.0.java.lang.NoClassDefFoundError: org/apache/hóa học/opencmis/khách hàng/api/SessionFactory

Tôi đã sử dụng cmis để cập nhật tài liệu trong Alfresco.

Tôi đã đăng ký một tài liệu Alfresco và đây là id tài liệu được lấy ra sau khi các phương pháp tiết kiệm: b08e8bce-1b88-489e-a357-1e6385f180a1

Bây giờ tôi muốn thay đổi nội dung này tệp theo nội dung khác. Tôi sử dụng phương pháp này:

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"); 
        } 
       } 
      } 



    } 

tôi gọi phương pháp này sử dụng mã này:

File file = new File("C:/test.pdf"); 
     saveVersioning(file, "test.pdf", "admin","admin","b08e8bce-1b88-489e-a357-1e6385f180a1"); 

tôi đã sử dụng jar này trong dự án java của tôi:

enter image description here

Tất cả các lọ được thêm đến đường dẫn lớp, nhưng khi tôi kiểm tra đơn đăng ký của mình, tôi nhận được lỗi này:

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 

4 máy chủ Alfresco Community My chứa jar này:

enter image description here

CẬP NHẬT:

tôi thấy rằng với Alfresco Community 4.0.0
tôi nên sử dụng hóa-opencmis-client 0.6.0alfresco-opencmis-extension-0.2.jar

cũng tôi nên sử dụng URL này trong mã của tôi: http://localhost:9080/alfresco/cmisatom

Tôi cố gắng không thành công để có được Juste phiên với CMIS sử dụng mã này:

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(); 

như tôi đã nói tôi đã sử dụng jar này:

enter image description here

Tôi đã tải xuống tất cả lib từ hóa học-opencmis-client-impl-0.6.0-with-dependencies.tar.gz và tôi cũng đã tải xuống jar này alfresco-opencmis-extension-0.2.jar

khi tôi kiểm tra tôi có cùng lỗi.

tôi đã thêm dòng này trong mã của tôi:

parameter.put(SessionParameter.OBJECT_FACTORY_CLASS, "org.alfresco.cmis.client.impl.AlfrescoObjectFactoryImpl"); 

Tôi nghĩ rằng vấn đề có liên quan đến phiên bản của jar mất tích và không liên quan đến mã java của tôi nhưng tôi cố gắng thay đổi nhưng không thành công dòng này:

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

với:

parameter.put(SessionParameter.ATOMPUB_URL, "http://localhost:9080/alfresco/service/cmis"); 
+0

Sử dụng Maven! Nó sẽ "ít phức tạp" thứ :) XD –

Trả lời

2

tôi không chắc chắn nếu điều này là thứ e câu trả lời đúng, nhưng hy vọng bạn sẽ tìm thấy lỗi và một số mẹo.

  1. Đầu tiên tải về latest CMIS Workbench hoặc tải về 0.6.0 version
  2. Sử dụng bàn làm việc để kết nối với Alfresco của bạn để kiểm tra xem tất cả mọi thứ đang làm việc, ví dụ tạo/đọc/cập nhật/xóa
  3. Đọc nhiều về CMIS here và nhiều mục khác ..
  4. Khi bạn đã đọc bạn muốn có phiên bản Alfresco cao hơn 4.0. Và nếu bạn cần một môi trường CMIS ổn định thì bạn nên nâng cấp lên 4.2.f hoặc thậm chí cao hơn.
  5. Mương dự án Java hiện tại của bạn và tải xuống 0.6.0 với các phụ thuộc mới từ trang tải xuống
  6. Đến điểm mà bạn có thể 'thực sự' đọc & lưu tệp.
  7. Trong thiết lập hiện tại của bạn, bạn không thể lưu tệp trên Alfresco và không nhận được NoClassDefFoundError và khi cập nhật nhận được lỗi. Hoặc bạn luôn gặp lỗi khi xây dựng hoặc bạn gặp phải một lỗi khác.
  8. Di chuyển sessionfactory và tạo mã phiên đến một init chung() hoặc phương pháp setupConnection() do đó bạn không có mã trùng lặp và do đó có nhiều cơ hội của những sai lầm
0

tôi sẽ cho rằng bạn chạy của bạn thử nghiệm với một classpath khác sau đó cho thấy trên các ảnh chụp màn hình.

Caused by: java.lang.ClassNotFoundException: org.apache.chemistry.opencmis.client.api.SessionFactory 
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1387) 

Bạn chạy thử nghiệm trong thùng chứa tomcat? Kiểm tra cẩn thận đường dẫn lớp khi bắt đầu kiểm tra. Nếu classpath thực sự có các phụ thuộc cmis thì hãy kiểm tra xung đột phiên bản máy khách cmis. Tất cả các phiên bản xung đột có thể được giải quyết bằng maven (ví dụ) một cách dễ dàng. Tôi khuyên bạn nên tạo dự án như dự án maven để vô hiệu hóa vấn đề này. Ngoài ra maven sẽ bao gồm tất cả các phụ thuộc cmis trong classpath khi bạn chạy thử nghiệm.

Các vấn đề liên quan