java Maven eclipse 不添加依赖
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2544422/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven eclipse does not add a dependency
提问by Kannan Ekanath
I have the following snippet in my pom.xml (Full pom attached below which can be executed)
我的 pom.xml 中有以下代码段(下面附有完整的 pom,可以执行)
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.5.3</version>
</dependency>
and in one of my Java files I refer a class org.aspectj.lang.ProceedingJoinPoint. When I do a "mvn clean install" it compiles and builds fine but when I do an eclipse:eclipse, and import the project in eclipse it gives me an error The import org.aspectj cannot be resolved. I checked the .classpath file that was generated and it does not have an entry to this file. I tried a "mvn dependency:tree" and it lists this fine.
在我的一个 Java 文件中,我引用了一个类org.aspectj.lang.ProceedingJoinPoint。当我执行“mvn clean install”时,它编译并构建得很好,但是当我执行 eclipse:eclipse 并在 eclipse 中导入项目时,它给了我一个错误The import org.aspectj cannot be resolved。我检查了生成的 .classpath 文件,但它没有该文件的条目。我尝试了一个“mvn dependency:tree”,它很好地列出了这个。
I don't have any fancy settings for not compiling any java files. It is just a routine pom which puzzles me.
我没有任何不编译任何 java 文件的花哨设置。这只是一个让我困惑的例行pom。
Can someone tell me what is going wrong here?
有人能告诉我这里出了什么问题吗?
UPDATE 1: I am using maven eclipse plugin Version: 2.7
更新 1:我使用的是 Maven Eclipse 插件版本:2.7
UPDATE 2: Just use pom below and do a mvn eclipse:clean eclipse:eclipsefrom the command line
更新 2:只需使用下面的 pom 并mvn eclipse:clean eclipse:eclipse从命令行执行
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ekanathk</groupId>
<artifactId>stackoverflow</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.5.3</version>
</dependency>
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.3</version>
</dependency>
</dependencies>
</project>
采纳答案by Pascal Thivent
I just tried to reproduce the problem and... couldn't. This is the .classpathI get after adding the aspectj:aspectjrt:jar:1.5.3 dependency to a freshly created project:
我只是试图重现该问题,但...不能。这是.classpath我将 aspectj:aspectjrt:jar:1.5.3 依赖项添加到新创建的项目后得到的结果:
<classpath>
<classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
<classpathentry kind="src" path="src/main/java" including="**/*.java"/>
<classpathentry kind="output" path="target/classes"/>
<classpathentry kind="var" path="M2_REPO/aspectj/aspectjrt/1.5.3/aspectjrt-1.5.3.jar">
<attributes>
<attribute value="jar:file:/home/pascal/.m2/repository/aspectj/aspectjrt/1.5.3/aspectjrt-1.5.3-javadoc.jar!/" name="javadoc_location"/>
</attributes>
</classpathentry>
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
</classpath>
What version of the maven eclipse plugin are you using? Did you configure it to use AJDT? Can you show your configuration?
您使用的是哪个版本的 maven eclipse 插件?您是否将其配置为使用 AJDT?你能显示你的配置吗?
回答by kopper
I had similar problem. Running mvn eclipse:cleanand then mvn eclipse:eclipsehelped.
我有类似的问题。跑mvn eclipse:clean,然后mvn eclipse:eclipse帮助。
回答by Tadeusz Kopec
I've had similar problem. Eclipse plugin for maven assumes Eclipse has its own support for AspectJ. So you need to tell it you have none (or tell it which version you have). Adding
我有过类似的问题。用于 maven 的 Eclipse 插件假定 Eclipse 有它自己对 AspectJ 的支持。所以你需要告诉它你没有(或者告诉它你有哪个版本)。添加
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<configuration>
<ajdtVersion>none</ajdtVersion>
</configuration>
</plugin>
to <build><plugins>section should help.
以<build><plugins>部分应帮助。

