Raffael
Raffael

Reputation: 20045

Module not found though everythings seems to be in place

(warning: am a complete Java-newbie!)

At this point I simply want to import com.mongodb.*. But this fails and I can't see why. I am using Intellij CE and Maven for the built.

The Java code:

package com.tengen;

import com.mongodb.*;

/**
 * Created by raffael on 04.06.14.
 */
public class HelloWorldMongoDBStyle {
    public static void main(String[] args) {

    }
}

(If I comment the importing of com.mongodb.* then the make process / compilation works fine - "compilation completed successfully")

The error message:

/home/raffael/M101J/src/main/java/com/tengen/HelloWorldMongoDBStyle.java
Error:(3, 1) java: package com.mongodb does not exist

The relevant part of the POM:

  <dependencies>
    <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongo-java-driver</artifactId>
      <version>2.11.4</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

The odd thing is that Intellij successfully downloads and integrates the module:

enter image description here

enter image description here

I can also confirm that the jar is located where the library settings assume it to be and that it contains a folder com/mongodb/ with a lot of class-files.

Any idea what the issue might be or how to figure it out?

Upvotes: 1

Views: 1296

Answers (1)

Joop Eggen
Joop Eggen

Reputation: 109557

It is probably a copy error: You got a test scope.

<scope>test</scope>

This means that only in test packages (src/main/test) an import is allowed. For unit tests. Removing the line will give the entire scope.

Upvotes: 1

Related Questions