Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse Maven dependency jar grayed out, can't import classes from it

I'm helping a friend configure a maven project with m2eclipse for the first time. We're both pretty unfamiliar with it and are encountering an issue where even though a dependency jar is showing up with packages in it under "maven dependencies" in the Project directory, if we try to import anything from any of that jar's packages, it can't find the class.

I noticed that the jars that are having issues are gray and not as opaque as the rest of the jars that are working.

What's strange is if you hover of the class name in the import, it shows a brief description of the class (from the documentation in the jar!) but it won't let me import it. All the other maven dependencies can be imported fine. Any ideas? We can't seem to even find what the darker icon means.

enter image description here enter image description here

Also, the pom.xml is dead simple:

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

  <groupId>com.something.portal.test</groupId>
  <artifactId>PortalFrontEndTests</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>PortalFrontEndTests</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <!-- Selenium -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>2.53.1</version>
    </dependency>

    <!-- TestNG -->
    <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.11</version>
        <scope>test</scope>
    </dependency>

  </dependencies>
</project>

I'm not sure what I'm missing here

like image 404
CustardBun Avatar asked Sep 05 '25 03:09

CustardBun


2 Answers

open your pom.xml file check for the name of the grayed out jar file change

<scope>test</scope>

to

<scope>compile</scope>
like image 163
Vishnu M. D. Avatar answered Sep 08 '25 19:09

Vishnu M. D.


I found the issue. It was because I had the class in the source directory instead of the test directory and both of the maven dependencies had been marked as "Visible only to test"

like image 45
CustardBun Avatar answered Sep 08 '25 19:09

CustardBun