简体   繁体   English

Maven在M2_REPO目录中创建子文件夹

[英]Maven creates sub folders in M2_REPO Directory

After running Maven - clean, I see sub folders in my M2_REPO folder. 运行Maven-clean之后,我在M2_REPO文件夹中看到了子文件夹。 junit.jar was created in M2_REPO/junit/junit/4.11/ alone with some other files. junit.jar与其他一些文件一起在M2_REPO / junit / junit / 4.11 /中创建。 Because of this sub folder structure, eclipse is not able to recognize the junit.jar file. 由于此子文件夹结构,eclipse无法识别junit.jar文件。 What am I missing? 我想念什么?

You're looking in the wrong directory. 您在错误的目录中查找。 Eclipse shouldn't read the jars directly from this directory, it is the local cache of what maven manages. Eclipse不应直接从此目录读取jar,它是maven管理的本地缓存。

The pom.xml is where you should put your dependencies, and eclipse will then use the maven libraries to get the required jar file, put it on the build path, and possibly cache it in the directory you are looking at. pom.xml是您应放置依赖项的位置,然后eclipse将使用maven库获取所需的jar文件,将其放在构建路径中,并可能将其缓存在您正在查看的目录中。

Note that if you want the junit jar file for testing purposes, the typical file in src/main/java will not see it, because testing source code goes in src/test/java. 请注意,如果您希望将junit jar文件用于测试目的,则src / main / java中的典型文件将看不到它,因为测试源代码位于src / test / java中。

This means that maven provides (through the libraries) (at least) two classpaths. 这意味着maven(至少通过库)提供两个类路径。 One for typical compilation and one for test compilation and execution. 一种用于典型编译,另一种用于测试编译和执行。 Adding in a <dependency> tag section puts it on the compilation and run paths; 在<dependency>标记部分中添加它,将其放在编译和运行路径中; but, to make it "test only" you need a nested <scope> tag. 但是,要使其成为“仅测试”,您需要嵌套的<scope>标记。

Maven correctly is creating those directories the first time it tries to acquire those artifacts. Maven在第一次尝试获取这些工件时正确地创建了这些目录。

For integrating maven and eclipse, try running mvn eclipse:eclipse 为了集成maven和eclipse,请尝试运行mvn eclipse:eclipse

This should enable eclipse to see the jars maven has downloaded. 这将使eclipse能够查看maven已下载的jar。

That is the path of the local M2 repository and the sub-folder structure is exactly how it should look. 这就是本地M2存储库的路径,而子文件夹结构正是它的外观。 Make sure that you import the project in eclipse as a maven project by doing 确保通过执行以下操作将eclipse中的项目作为maven项目导入

File -> Import -> Maven -> Existing maven project

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM