【问题标题】:Maven: package net.jcip.annotations does not existMaven:包 net.jcip.annotations 不存在
【发布时间】:2015-05-07 07:10:56
【问题描述】:

我想在我的 Java 代码中使用 @net.jcip.annotations.NotThreadSafe。我试图导入它是 pom.xml 中项目的依赖项,如下所示。但是,我仍然收到错误消息:我的导入有问题吗?

包 net.jcip.annotations 不存在

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18</version>
    <dependencies>
        <dependency>
            <groupId>org.apache.maven.surefire</groupId>
            <artifactId>surefire-junit47</artifactId>
            <version>2.18</version>
        </dependency>
        <dependency>
            <groupId>net.jcip</groupId>
            <artifactId>jcip-annotations</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
    <configuration>
        {...}
    </configuration>
  </plugin>

【问题讨论】:

  • 这个错误出现在哪里,你使用的是什么IDE?
  • 我正在使用 IntelliJ。它出现在我在 IntelliJ 中编译(Ctrl + F9)和运行 maven 目标“test”时。
  • net.jcip Maven 导入是否正常工作,或者有些东西是红色的?
  • 我刚刚在我的 IntelliJ 项目中尝试过这个,它可以正常工作。您是将@NotThreadSafe 注释放在class 还是method 上?它被设计为放置在一个class上。将其放在方法上会提示 IntelliJ 将其变为红色。
  • SHIFT + CTRL + ALT + S 你看到那里列出了 jcip-annotations:1.0 吗?

标签: java maven pom.xml


【解决方案1】:

如果你像上面那样做,你只需将依赖项添加到 maven-surefire-plugin 的类路径中,这不是你想要的。你必须像这样在你的 pom 中给出它:

<project...>
  <dependencies>
    <dependency>
       <groupId>net.jcip</groupId>
       <artifactId>jcip-annotations</artifactId>
       <version>1.0</version>
    </dependency>
    ...
  </dependencies>

</project>

此外,鉴于对surefire-juni47 的依赖不是必需的,因为surefire 插件会自行处理此问题。所以这看起来像这样:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.18</version>
    <configuration>
        {...}
    </configuration>
</plugin>

【讨论】:

    猜你喜欢
    • 2013-02-19
    • 2018-12-23
    • 2021-08-10
    • 2019-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    相关资源
    最近更新 更多