Home > other >  Maven - package graphstream does not exist
Maven - package graphstream does not exist

Time:05-04

I've added a 'graphstream' dependency to my pom.xml file in a maven project, like so:

<dependency>
     <artifactId>gs-core</artifactId>
     <groupId>org.graphstream</groupId>
     <version>2.0</version>
</dependency>

And then I've tried to import 'graphstream' to my java file:

import org.graphstream.*;

But when I'm running mvn install I'm getting the following error

package org.graphstream does not exist

What did I do wrong?

CodePudding user response:

I've checked the source code: there is no package org.graphstream really. There is a folder org/graphstream that contains other folders. You may use import org.graphstream.graph.*; as this is a real package. You probably want to recursively import everything, but it's not how Java works. I give you a quote from this conversation:

There aren't really "sub-packages." The JLS actually uses that term, but I don't know why. There's no real hierarchy, other than the one on the filesystem and the logical one implied by the names. As far as Java is concerned, the packages have no relation to each other.

Here is my dummy code how imports should look in your project:

import org.graphstream.graph.*;

public class Test {

    public static void main(String[] args) {
        System.out.printf("Import works: %s", Graph.class);
    }
}

I hope it answers your question. I've also created a github repo with my sandbox. Just please check out the code and run mvn compile exec:java -Dexec.mainClass="org.test.Test" in the project's root. If it doesn't work, please show me the output.

  • Related