Eclipse Maven依赖项jar变灰,无法从中导入类 [英] Eclipse Maven dependency jar grayed out, can't import classes from it

查看:104
本文介绍了Eclipse Maven依赖项jar变灰,无法从中导入类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次帮助朋友用m2eclipse配置一个maven项目.我们都不太熟悉它,并且遇到一个问题,即使依赖项jar在Project目录中的"maven依赖项"下显示了其中的程序包,如果我们尝试从该jar的任何程序包中导入任何内容,找不到课程.

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.

奇怪的是,如果您在导入中悬停了类名,它会显示该类的简短说明(来自jar中的文档!),但不会让我导入它.所有其他的Maven依赖项都可以很好地导入.有任何想法吗?我们似乎甚至找不到深色图标的含义.

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.

此外,pom.xml非常简单:

Also, the pom.xml is dead simple:

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

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>

我不确定这里缺少什么

推荐答案

我发现了问题.这是因为我将类放在源目录中而不是测试目录中,并且两个maven依赖项都被标记为仅可测试".

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"

这篇关于Eclipse Maven依赖项jar变灰,无法从中导入类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆