I'm starting with Alfresco. I'm following a tutorial book Alfresco CMIS, and, to make a CMIS Client JAVA I start by using the Maven Quick Start artifact: mvn archetype:generate -DgroupId=com.my.company.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
and this create a project with a directory structure and a java file com.my.company.app.App.java to put this code:
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");
}
}
And configure the pom.xml with that:
<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>
And in the same package of the App class, we create the file CmisClient.java with this:
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;
}
}
I'm trying to run the command mvn compile exec:java -Dexec.mainClass="com.mycompany.app.App"
to run the code, indicated by the book. But, i got the error: http://pastebin.com/kK3YvPRF
I put on the pastebin because I think that with all debug it's more easy for understand. What is my error?
EDIT: i already try to import org.apache.chemistry.opencmis.client.api in the java file, but without success... I think maven do this, but anything is wrong.
I solve it! I put the project in IntelliJ IDEA and I import .jar libraries that I downloaded from here http://chemistry.apache.org/java/opencmis.html and i make all imports needed.
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;
If anyone needs, it's that, for that problem.