簡體   English   中英

設置M2_REPO類路徑

[英]Setting up M2_REPO classpath

我有幾個與此相對應的問題。

  1. 什么是M2_REPO?
  2. 這個命令做什么用的?

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

  3. 為什么我們需要做上述事情?

  1. M2_REPO是一個變量,用於定義磁盤上maven 2存儲庫的位置
  2. 這意味着:將M2_REPO的定義添加到定義eclipse工作空間的XML文件中
  3. 如果需要,您可以手動執行相同操作。 這就是我個人所做的。 只需轉到Window / Preferences,然后選擇Java / Build Path / Classpath Variables。 一旦你做到了,你可以享受maven與eclipse的集成。 每次向pom.xml添加新依賴項時,請運行

    mvn eclipse:eclipse

並刷新工作區,將所有新庫放入項目的類路徑中。

編輯

這個答案寫於5年前。 現在任何eclipse發行版都有maven插件,所以eclipse可以直接打開maven項目。 您添加到pom.xml的每個依賴項都會自動下載,並且幾乎可以立即使用。

轉到Windows->首選項 - > Java - >構建路徑 - >類路徑變量 - >新建並添加以下內容;

Name = M2_REPO(或者您為Maven存儲庫提供的名稱)Path = C:\\ Users \\ Administrator.m2 \\ repository(我的保存在此處)

不,您不希望所有maven工件遍布eclipse項目/包資源管理器中的Libraries文件夾。

你想要所有的maven工件很好地包裝在一個子文件夾下

Java資源>庫> Maven依賴項

就像在gd'old時代一樣。

在完成其余答案中建議的所有內容之后,您所獲得的所有內容仍然是在pkg / prj資源管理器的頂級列表中排列的所有maven文物,原因是您剛剛升級到最新版本最好的Eclipse版本,你所擁有的m2eclipse插件版本還沒有與Eclipse版本競爭。

也不想每次添加新的maven依賴項時都運行mvn eclipse:eclipse或eclipse:config .. 這完全違背了maven的意思。

解決

雖然m2eclipse在打屁股的新日食版本中在黑暗中摸索,

  1. 保存當前的.classpath。

  2. 用POME.C(普通的舊maven eclipse .classpath)替換你的eclipse .classpath: http//code.google.com/p/synthfuljava/source/browse/apps/durian/.classpath

  3. 請記住將java版本更改為您的版本。

  4. 請記住添加在orig .classpath中找到的所有自定義非maven路徑。

  5. 現在,做一個好公民,並為這個eclipse版本提交一個m2eclipse錯誤(如果我還沒有),告訴他們m2eclipse不構建good'ol POME.C,解釋POME.C是多么可愛和方便。

但是由於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