有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

eclipse如何在java项目中设置maven本地repo

我是马文的新手。我和我的团队正试图在git上与maven合作,但当我在git上共享代码时。类路径文件具有指向我的用户位置的依赖项:

<classpathentry kind="lib" path="C:/Users/MY_USERNAME/.m2/repository/org/springframework/security/spring-security-crypto/5.1.0.RELEASE/spring-security-crypto-5.1.0.RELEASE.jar" sourcepath="C:/Users/MY_USERNAME/.m2/repository/org/springframework/security/spring-security-crypto/5.1.0.RELEASE/spring-security-crypto-5.1.0.RELEASE-sources.jar">
    <attributes>
        <attribute name="maven.pomderived" value="true"/>
        <attribute name="maven.groupId" value="org.springframework.security"/>
        <attribute name="maven.artifactId" value="spring-security-crypto"/>
        <attribute name="maven.version" value="5.1.0.RELEASE"/>
        <attribute name="maven.scope" value="compile"/>
    </attributes>
</classpathentry>

这会导致我的团队成员出现配置问题

  • 有没有办法在我的项目中添加.m2文件夹,然后在构建路径中引用它
  • 建议这样做吗

我不想把我的孩子排除在外。类路径文件,因为我希望我的团队成员接收所有的构建路径配置,而不必自己执行


共 (1) 个答案

  1. # 1 楼答案

    Maven附带了一个Eclipse插件,允许您轻松地维护您的应用程序。基于pom的类路径文件。xml(对于maven 1.x用户,可以使用project.xml)(参见docs

    • 初始设置

      要初始化maven对更新eclipse类路径的支持,首先需要在vim中执行以下命令,在eclipse工作区中设置M2_REPO(或MAVEN_REPOfor 1.x)类路径变量:

      maven 2。x:

      :MvnRepo

      maven 1。x:

      :MavenRepo

    • 更新您的。类路径

      完成初始设置后,更新Eclipse。类路径文件与在命令行执行以下操作一样简单:

      maven 2。x:

      mvn eclipse:eclipse

      maven 1。x:

      maven eclipse

      或在Vim中:

      maven 2。x:

      :Mvn eclipse:eclipse

      maven 1。x:

      :Maven eclipse

    在您的情况下,每一个团队成员都应该在每次他/她想要更新pom中彼此更新的依赖项时遵循此过程。xml

    其他读数

    附加注释

    使用Gradle,您可以这样做:

    buildscript {
        // ...
        repositories {
            mavenLocal()      // this uses your local maven repository
            // mavenCentral() // this uses maven central repository
            // maven { url "<some-additional-url-here>" }
        }
        dependencies {
            // ...
        }
    }