【发布时间】: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.jcipMaven 导入是否正常工作,或者有些东西是红色的? -
我刚刚在我的 IntelliJ 项目中尝试过这个,它可以正常工作。您是将@NotThreadSafe 注释放在class 还是method 上?它被设计为放置在一个class上。将其放在方法上会提示 IntelliJ 将其变为红色。
-
SHIFT + CTRL + ALT + S你看到那里列出了 jcip-annotations:1.0 吗?