Sample client
You can make use of the OpenKM Maven Repository and the right SDK version. This is a sample pom.xml configuration:
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.openkm.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>openkm.com</id>
<name>OpenKM Maven Repository</name>
<url>https://maven.openkm.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.openkm</groupId>
<artifactId>sdk4j</artifactId>
<version>3.29</version>
</dependency>
</dependencies>
</project>
Your first class:
package com.openkm;
import com.openkm.sdk4j.OKMWebservicesFactory;
import com.openkm.sdk4j.bean.Folder;
import com.openkm.sdk4j.impl.OKMWebservices;
public class Test {
public static void main(String[] args) {
String host = "http://localhost:8080/openkm";
String user = "okmAdmin";
String password = "admin";
OKMWebservices ws = OKMWebservicesFactory.getInstance(host);
try {
ws.login(user, password);
for (Folder fld : ws.folder.getFolderChildren("4f873d10-654e-4d99-a94f-15466e30a0f6")) {
System.out.println("Folder -> " + fld.getPath());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
How to build a project with dependencies
Using spring-boot-maven-plugin ( recommended )
The plugin can be used to create an executable 'fat' JAR. The extension of the created file is "WAR" but can be executed as a regular "JAR" file from the command line:
$> java -jar sample-1.0.war
More information at:
- https://docs.spring.io/spring-boot/docs/1.1.x/reference/html/howto-build.html
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.openkm.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>openkm.com</id>
<name>OpenKM Maven Repository</name>
<url>https://maven.openkm.com</url>
</repository>
<repository>
<id>apache.org</id>
<name>Apache Maven Repository</name>
<url>https://repo.maven.apache.org/maven2/.</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.openkm</groupId>
<artifactId>sdk4j</artifactId>
<version>3.29</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- https://docs.spring.io/spring-boot/docs/1.1.x/reference/html/howto-build.html -->
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- version below is mandatory because project does not use the parent POM
version 2.7.x works with jsk 1.8, the upper version seems to require JDK 11-->
<version>2.7.12</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.company.Sample1</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Using executable-packer-maven-plugin ( recommended )
More information at:
- https://github.com/nthuemmel/executable-packer-maven-plugin
- https://stackoverflow.com/questions/11758594/how-do-i-put-all-required-jar-files-in-a-library-folder-inside-the-final-jar-fil
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.openkm.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>openkm.com</id>
<name>OpenKM Maven Repository</name>
<url>https://maven.openkm.com</url>
</repository>
<repository>
<id>apache.org</id>
<name>Apache Maven Repository</name>
<url>https://repo.maven.apache.org/maven2/.</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.openkm</groupId>
<artifactId>sdk4j</artifactId>
<version>3.29</version>
</dependency>
</dependencies>
<build>
<plugins>
<!-- how to create maven executable with libs into the jar https://github.com/nthuemmel/executable-packer-maven-plugin
https://stackoverflow.com/questions/11758594/how-do-i-put-all-required-jar-files-in-a-library-folder-inside-the-final-jar-fil -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>de.ntcomputer</groupId>
<artifactId>executable-packer-maven-plugin</artifactId>
<version>1.0.1</version>
<configuration>
<mainClass>com.company.Sample1</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>pack-executable-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Using maven-shade-plugin
If you use "maven-assembly-plugin" rather "maven-shade-plugin" you will get an error "missing MessageBodyWriter" while uploading a new file across the SDK.
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.openkm.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.compiler>1.8</java.compiler>
<sdk4j.version>3.29</sdk4j.version>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<maven-shade-plugin.version>2.4.3</maven-shade-plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>openkm.com</id>
<name>OpenKM Maven Repository</name>
<url>https://maven.openkm.com</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.openkm</groupId>
<artifactId>sdk4j</artifactId>
<version>${sdk4j.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.compiler}</source>
<target>${java.compiler}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven-shade-plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.openkm.Main</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/javax.ws.rs.ext.MessageBodyWriter</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>