gpt4 book ai didi

java - CMIS 客户端 JAVA - Alfresco

转载 作者:行者123 更新时间:2023-11-30 10:57:09 26 4
gpt4 key购买 nike

我从 Alfresco 开始。我正在学习一本教程书 Alfresco CMIS,并且,为了制作一个 CMIS 客户端 JAVA,我首先使用 Maven 快速入门 Artifact :mvn archetype:generate -DgroupId=com.my.company.app -DartifactId=my- app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false 这将创建一个具有目录结构的项目和一个 java 文件 com.my.company.app.App.java 来放置此代码:

  package com.mycompany.app;


public class App
{
public static void main( String[] args )
{
CmisClient cmisClient = new CmisClient();
String connectionName = "testeConn";
Session session = cmisClient.getSession(connectionName, "admin", "admin");
}
}

然后用它配置 pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- Bring in the OpenCMIS library for talking to CMIS
servers -->
<dependency>
<groupId>org.apache.chemistry.opencmis</groupId>
<artifactId>chemistry-opencmis-client-impl
</artifactId>
<version>0.13.0</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

在 App 类的同一个包中,我们使用以下内容创建文件 CmisClient.java:

public class CmisClient {
private static Log logger = LogFactory.getLog(CmisClient.class);
private static Map<String, Session> connections = new
ConcurrentHashMap<String, Session>();
public CmisClient() {
}
public Session getSession(
String connectionName, String username, String pwd) {
Session session = connections.get(connectionName);
if (session == null) {
logger.info("Not connected, creating new connection to" +
" Alfresco with the connection id (" + connectionName +
")");
// No connection to Alfresco available, create a new one
SessionFactory sessionFactory =
SessionFactoryImpl.newInstance();
Map<String, String> parameters = new HashMap<String,
String>();
parameters.put(SessionParameter.USER, username);
parameters.put(SessionParameter.PASSWORD, pwd);
parameters.put(SessionParameter.ATOMPUB_URL,
"http://localhost:8080/alfresco/api/-default-/cmis/versions/1.1/atom");
parameters.put(SessionParameter.BINDING_TYPE,
BindingType.ATOMPUB.value());
parameters.put(SessionParameter.COMPRESSION, "true");
parameters.put(SessionParameter.CACHE_TTL_OBJECTS, "0");
// If there is only one repository exposed (e.g. Alfresco),
// these lines will help detect it and its ID
List<Repository> repositories =
sessionFactory.getRepositories(parameters);
Repository alfrescoRepository = null;
if (repositories != null && repositories.size() > 0) {
logger.info("Found (" + repositories.size() +
") Alfresco repositories");
alfrescoRepository = repositories.get(0);
logger.info("Info about the first Alfresco repo [ID=" +
alfrescoRepository.getId() + "][name=" +
alfrescoRepository.getName() + "][CMIS ver supported=" +
alfrescoRepository.getCmisVersionSupported() + "]");
} else {
throw new CmisConnectionException(
"Could not connect to the Alfresco Server, " +
"no repository found!");
}
// Create a new session with the Alfresco repository
session = alfrescoRepository.createSession();
// Save connection for reuse
connections.put(connectionName, session);
} else {
logger.info("Already connected to Alfresco with the " +
"connection id (" + connectionName + ")");
}
return session;
}
}

我正在尝试运行命令 mvn compile exec:java -Dexec.mainClass="com.mycompany.app.App" 来运行书中指示的代码。但是,我得到了错误:http://pastebin.com/kK3YvPRF

我放上了 pastebin,因为我认为所有调试都更容易理解。我的错误是什么?

编辑:我已经尝试在 java 文件中导入 org.apache.chemistry.opencmis.client.api,但没有成功...我认为 maven 会这样做,但有任何问题。

最佳答案

我解决了!我将项目放入 IntelliJ IDEA 并导入从此处下载的 .jar 库 http://chemistry.apache.org/java/opencmis.html我做所有需要的进口。

package com.mycompany.app;

import org.apache.chemistry.opencmis.client.api.Repository;
import org.apache.chemistry.opencmis.client.api.Session;
import org.apache.chemistry.opencmis.client.api.SessionFactory;
import org.apache.chemistry.opencmis.client.runtime.SessionFactoryImpl;
import org.apache.chemistry.opencmis.commons.SessionParameter;
import org.apache.chemistry.opencmis.commons.enums.BindingType;
import org.apache.chemistry.opencmis.commons.exceptions.CmisConnectionException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

如果有人需要,那就是那个问题。

关于java - CMIS 客户端 JAVA - Alfresco,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32742858/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com