简体   繁体   English

设置M2_REPO类路径

[英]Setting up M2_REPO classpath

I have a few questions corresponding to this. 我有几个与此相对应的问题。

  1. What is M2_REPO? 什么是M2_REPO?
  2. What does this command do? 这个命令做什么用的?

    mvn -Declipse.workspace=<your_workspace_location> eclipse:add-maven-repo

  3. Why do we need to do the above? 为什么我们需要做上述事情?

  1. M2_REPO is a variable that defines where maven 2 repository is on your disk M2_REPO是一个变量,用于定义磁盘上maven 2存储库的位置
  2. This means: add definition of M2_REPO to XML file that defines the eclipse workspace 这意味着:将M2_REPO的定义添加到定义eclipse工作空间的XML文件中
  3. You can do the same manually if you want. 如果需要,您可以手动执行相同操作。 That is what I personally did. 这就是我个人所做的。 Just go to Window/Preferences and then choose Java/Build Path/Classpath Variables. 只需转到Window / Preferences,然后选择Java / Build Path / Classpath Variables。 Once you did it you can enjoy maven integration with eclipse. 一旦你做到了,你可以享受maven与eclipse的集成。 Every time you add new dependency to your pom.xml, run 每次向pom.xml添加新依赖项时,请运行

    mvn eclipse:eclipse mvn eclipse:eclipse

and refresh you workspace you get all new libraries into classpath of your project. 并刷新工作区,将所有新库放入项目的类路径中。

EDIT 编辑

This answer was written 5 years ago. 这个答案写于5年前。 These days any eclipse distribution has maven plugin, so eclipse can open maven project directly. 现在任何eclipse发行版都有maven插件,所以eclipse可以直接打开maven项目。 Every dependency you add to your pom.xml is automatically downloaded and almost immediately ready to use. 您添加到pom.xml的每个依赖项都会自动下载,并且几乎可以立即使用。

Go to Windows-> Preference -> Java ->Build Path -> Classpath Variables -> New and add the following ; 转到Windows->首选项 - > Java - >构建路径 - >类路径变量 - >新建并添加以下内容;

Name = M2_REPO (or what ever name you gave for your Maven repository) Path = C:\\Users\\Administrator.m2\\repository (Mine is saved here) Name = M2_REPO(或者您为Maven存储库提供的名称)Path = C:\\ Users \\ Administrator.m2 \\ repository(我的保存在此处)

No, you don't want all your maven artifacts strewn all over the Libraries folder in eclipse project/package explorer. 不,您不希望所有maven工件遍布eclipse项目/包资源管理器中的Libraries文件夹。

You want all the maven artifacts wrapped nicely under one subfolder of 你想要所有的maven工件很好地包装在一个子文件夹下

Java Resources > Libraries > Maven Dependencies Java资源>库> Maven依赖项

just like in the gd'old days. 就像在gd'old时代一样。

After you done everything suggested in the rest of the answers, and all you get is still having all your maven artefacts strewn over the top level of the pkg/prj explorer's top level listing, the reason is because you have just upgraded to the latest and greatest Eclipse version, and the m2eclipse plugin version you have has not raced uptodate with that Eclipse version. 在完成其余答案中建议的所有内容之后,您所获得的所有内容仍然是在pkg / prj资源管理器的顶级列表中排列的所有maven文物,原因是您刚刚升级到最新版本最好的Eclipse版本,你所拥有的m2eclipse插件版本还没有与Eclipse版本竞争。

You ALSO don't want to run mvn eclipse:eclipse or eclipse:config.. everytime you add new maven dependencies. 也不想每次添加新的maven依赖项时都运行mvn eclipse:eclipse或eclipse:config .. That simply goes against what maven stands for. 这完全违背了maven的意思。

Work around 解决

While m2eclipse is groping around in the dark in your spanking new eclipse version, 虽然m2eclipse在打屁股的新日食版本中在黑暗中摸索,

  1. Save your current .classpath. 保存当前的.classpath。

  2. replace your eclipse .classpath with the POME.C (plain old maven eclipse .classpath): http://code.google.com/p/synthfuljava/source/browse/apps/durian/.classpath . 用POME.C(普通的旧maven eclipse .classpath)替换你的eclipse .classpath: http//code.google.com/p/synthfuljava/source/browse/apps/durian/.classpath

  3. Remember to change the java version to yours. 请记住将java版本更改为您的版本。

  4. Remember to add back all your custom non-maven paths, found in your orig .classpath. 请记住添加在orig .classpath中找到的所有自定义非maven路径。

  5. Now, be a good citizen and go file an m2eclipse bug (if I haven't yet) for this eclipse version, telling them the m2eclipse is not constructing the good'ol POME.C, explaining how lovely and convenient that POME.C is . 现在,做一个好公民,并为这个eclipse版本提交一个m2eclipse错误(如果我还没有),告诉他们m2eclipse不构建good'ol POME.C,解释POME.C是多么可爱和方便。

But since googlecode is going away this august (that's a pain, google), here is the body of the file. 但是由于googlecode正在消失这个八月(这是痛苦,谷歌),这里是文件的正文。

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
  <classpathentry kind="src" output="target/classes" path="src/main/java">
    <attributes>
      <attribute name="optional" value="true"/>
      <attribute name="maven.pomderived" value="true"/>
    </attributes>
  </classpathentry>
  <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
    <attributes>
      <attribute name="maven.pomderived" value="true"/>
    </attributes>
  </classpathentry>
  <classpathentry kind="src" output="target/test-classes" path="src/test/java">
    <attributes>
      <attribute name="optional" value="true"/>
      <attribute name="maven.pomderived" value="true"/>
    </attributes>
  </classpathentry>
  <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
    <attributes>
      <attribute name="maven.pomderived" value="true"/>
      <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
    </attributes>
  </classpathentry>
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
    <attributes>
      <attribute name="maven.pomderived" value="true"/>
    </attributes>
  </classpathentry>
  <classpathentry kind="output" path="target/classes"/>
</classpath>

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

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