1

I'm using VSCode on Ubuntu version 22.04.2, to implement and run some tests according to the GridDB docs available on https://docs.griddb.net/gettingstarted/java/#schema-creation, but I'm unable to run the code because of the following error:

"The import com.toshiba cannot be resolved-Java"

My Java file is:

import com.toshiba.mwcloud.gs.*;

public class GridDbTests{
    public static void main(String[] args)
    {
        Properties props = new Properties();
        props.setProperty("notificationAddress", "239.0.0.1");
        props.setProperty("notificationPort", "31999");
        props.setProperty("clusterName", "defaultCluster");
        props.setProperty("user", "admin");
        props.setProperty("password", "admin");
        GridStore store = GridStoreFactory.getInstance().getGridStore(props);
    }
}

And the lauch.json file is:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "java",
            "name": "GridDbTests.java",
            "request": "launch",
            "mainClass": "GridDbTests"
        }
    ]
}

What i'm doing wrong?

diegao15
  • 61
  • 3

1 Answers1

0

Well, com.toshiba is not a package thats contained the the JRE or JDK, but a 3rd party dependency.

The GridDB documentation tells you to compile the code manually, using

export CLASSPATH=$CLASSPATH:/usr/share/java/gridstore.jar
$ javac Sample1.java

However, VSCode will not know about this. According to the VSCode documentation under https://code.visualstudio.com/docs/java/java-project, you can add the gridstore.jar by following these steps:

Manage dependencies for unmanaged folder
If your project is an unmanaged folder without any build tools. You can manage the dependencies by clicking the + icon or the - icon on the Referenced Libraries node or the items under it, or you can just directly drag your jar libraries to the node Referenced Libraries.

Dependency Management

The better solution will be to properly learn how to use a dependency management tool, for example Maven.

The aforementioned VSCode documentation already contains information about Maven, and the GridDB documentation also has a page on how to use GridDB with Maven:

https://griddb.net/en/blog/using-maven-to-develop-griddb-applications/

Basically, you need to manually register the jar with Maven via

mvn install:install-file -Dfile=/usr/share/java/gridstore.jar -DgroupId=com.toshiba.mwcloud \
    -DartifactId=gs -Dversion=4.0 -Dpackaging=jar

And then add the following to your pom.xml (in the dependencies section):

<dependency>
        <groupId>com.toshiba.mwcloud</groupId>
        <artifactId>gs</artifactId>
        <version>4.0</version>
</dependency>

VSCode will usually automatically pick up changes to the pom.xml, if it does not, right click rhe project and hit Maven / Reload Project

Polygnome
  • 7,639
  • 2
  • 37
  • 57