0
votes

I'm trying to get started with the java-client. That's the Cos docs: https://console.bluemix.net/docs/services/cloud-object-storage/libraries/java.html#java

Before saying what I did - I just want to be able to run the example code. I've been stuck on this simple thing for 2 days and will try any solution you will suggest.

I followed this steps:

git clone https://github.com/IBM/ibm-cos-sdk-java.git
 Open IntelliJ->Import Project->select the path to ibm-cos-sdk-java->Import project from existing model (select maven)->next->next

Now I simply want to add the code and run it.

First try - i've tried pasting the code "CosExample.java" at the working directory created. BUT - red circle appears, and there isn't a way to run the file. (What does this symbol mean in IntelliJ? (red circle on bottom-left corner of file name, with 'J' in it)) 1 1 Second try - i've tried opening new directory (named "S3Proj") and put the code in it at the right structure. like here. Also, to fix the red circle, I marked the java directory as "Source" so it will be able to be run. But now everything won't compile. enter image description here What should I do ? Thanks

Edit: After @PatrickB comment, i'm adding my first try - just using maven dependency of com.ibm.cos

Without cloning the project. It doesn't work because the line

import com.ibm.oauth.BasicIBMOAuthCredentials;

isn't compiling. (The rest does compile) 3

The pom file for this try:

    <?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>S3Operation</groupId>
    <artifactId>S3Operation</artifactId>
    <version>1.0-SNAPSHOT</version>
    <dependencies>
        <dependency>
            <groupId>com.ibm.cos</groupId>
            <artifactId>ibm-cos-java-sdk</artifactId>
            <version>2.0.0</version>
        </dependency>
    </dependencies>

</project>

Last edit: SOLVED There is a bad import in the docs so it didn't compile.

Here https://console.bluemix.net/docs/services/cloud-object-storage/libraries/java.html#java?cm_sp=dw-bluemix--nospace--answers

This import won't compile:

import com.ibm.oauth.BasicIBMOAuthCredentials;

This is the right import:

import com.ibm.cloud.objectstorage.oauth.BasicIBMOAuthCredentials;

1
First case - file is not located under soures root. Second case - your root module doesn't contain needed dependency (<artifactId>ibm-cos-java-sdk-core</artifactId> ) - y.bedrov
@y.bedrov please can you give me more details? The pom file DOES contains that dependency. Second - I marked the 'java' dir as source. What should I do differently? - jonb

1 Answers

1
votes

I wouldn't clone the sdk source into your project. A more efficient way of using the cos sdk would be to create a maven project, adding the cos sdk dependency to your pom.xml e.g.

<dependency>
<groupId>com.ibm.cos</groupId>
<artifactId>ibm-cos-java-sdk</artifactId>
<version>2.0.0</version>
<type>pom</type>
</dependency>

Assuming maven is installed correctly this will automatically pull the sdk archives into your project from maven central.Then add your client code such as CosExample to src/main/java folder.