Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Eclipse/Maven:处理可重用库和相互依赖项目的最佳方法?_Eclipse_Maven_Dependencies - Fatal编程技术网

Eclipse/Maven:处理可重用库和相互依赖项目的最佳方法?

Eclipse/Maven:处理可重用库和相互依赖项目的最佳方法?,eclipse,maven,dependencies,Eclipse,Maven,Dependencies,在.NET世界工作了很长时间后,我刚刚回到Java/Eclipse世界。我对Maven也有点陌生,并掌握了窍门,但我有点进退两难 我目前正在开发几个Spring引导服务。这两个库都依赖于我开发的新库,我计划在其他项目中广泛重用这些库 为了方便起见,我开始在一个空的基于POM的父项下设置3个eclipse项目作为模块: 母体聚甲醛 服务1 POM LibB-POM 利巴波姆酒店 其中LibB依赖于LibA,Service1同时依赖于LibA和LibB 然而,随后出现了对Service2的需求,这将

在.NET世界工作了很长时间后,我刚刚回到Java/Eclipse世界。我对Maven也有点陌生,并掌握了窍门,但我有点进退两难

我目前正在开发几个Spring引导服务。这两个库都依赖于我开发的新库,我计划在其他项目中广泛重用这些库

为了方便起见,我开始在一个空的基于POM的父项下设置3个eclipse项目作为模块:

母体聚甲醛

  • 服务1 POM
  • LibB-POM
  • 利巴波姆酒店
  • 其中LibB依赖于LibA,Service1同时依赖于LibA和LibB

    然而,随后出现了对Service2的需求,这将取决于LibA

    因此,我决定摆脱父POM,使Service1、LibA、LibB和现在的Service2独立于eclipse/maven项目。我认为这将允许我在Git中独立管理它们

    我尝试在项目存储库中定义,在其中我可以将LibA和libbjar包含在Servcie1、Servcie2和LibB中(因为LibB依赖于LibA)。然而,eclipse/maven似乎没有意识到这一点。。。它似乎没有拿起jar,而是直接引用下面的lib项目(参见屏幕截图)

    这里最好的方法是什么

    cx配置服务POM:

    <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/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath />
    </parent>
    
    <groupId>com.esi.cx</groupId>
    <artifactId>cx-config-service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <!-- Leaving out irrelevant dependencies for brevity ... -->
        <dependency>
            <groupId>com.esi.cx</groupId>
            <artifactId>cx-utility</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.esi.cx</groupId>
            <artifactId>cx-genesys</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    
    <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/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.esi.cx</groupId>
    <artifactId>cx-genesys</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <repositories>
        <repository>
            <id>repo</id>
            <name>repo</name>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <url>file://${project.basedir}/repo</url>
        </repository>
    </repositories>
    
    <dependencies>
        <!-- Leaving out irrelevant dependencies for brevity ... -->
        <dependency>
            <groupId>com.esi.cx</groupId>
            <artifactId>cx-utility</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    
    <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/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.esi.cx</groupId>
    <artifactId>cx-utility</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <!-- Leaving out irrelevant dependencies for brevity ... -->
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    
    
    4.0.0
    org.springframework.boot
    spring启动程序父级
    1.4.2.1发布
    com.esi.cx
    cx配置服务
    1.0.0-SNAPSHOT
    1.7
    UTF-8
    com.esi.cx
    cx实用程序
    1.0.0-SNAPSHOT
    com.esi.cx
    cx基因系统
    1.0.0-SNAPSHOT
    org.apache.maven.plugins
    maven编译器插件
    3.3
    ${java.version}
    ${java.version}
    org.springframework.boot
    springbootmaven插件
    

    cx genesys POM:

    <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/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath />
    </parent>
    
    <groupId>com.esi.cx</groupId>
    <artifactId>cx-config-service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <!-- Leaving out irrelevant dependencies for brevity ... -->
        <dependency>
            <groupId>com.esi.cx</groupId>
            <artifactId>cx-utility</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.esi.cx</groupId>
            <artifactId>cx-genesys</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    
    <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/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.esi.cx</groupId>
    <artifactId>cx-genesys</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <repositories>
        <repository>
            <id>repo</id>
            <name>repo</name>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <url>file://${project.basedir}/repo</url>
        </repository>
    </repositories>
    
    <dependencies>
        <!-- Leaving out irrelevant dependencies for brevity ... -->
        <dependency>
            <groupId>com.esi.cx</groupId>
            <artifactId>cx-utility</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    
    <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/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.esi.cx</groupId>
    <artifactId>cx-utility</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <!-- Leaving out irrelevant dependencies for brevity ... -->
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    
    
    4.0.0
    com.esi.cx
    cx基因系统
    1.0.0-SNAPSHOT
    1.7
    UTF-8
    回购
    回购
    真的
    忽视
    假的
    文件://${project.basedir}/repo
    com.esi.cx
    cx实用程序
    1.0.0-SNAPSHOT
    org.apache.maven.plugins
    maven编译器插件
    3.3
    ${java.version}
    ${java.version}
    

    cx实用程序POM:

    <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/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath />
    </parent>
    
    <groupId>com.esi.cx</groupId>
    <artifactId>cx-config-service</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <!-- Leaving out irrelevant dependencies for brevity ... -->
        <dependency>
            <groupId>com.esi.cx</groupId>
            <artifactId>cx-utility</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>com.esi.cx</groupId>
            <artifactId>cx-genesys</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
    
    <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/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.esi.cx</groupId>
    <artifactId>cx-genesys</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <repositories>
        <repository>
            <id>repo</id>
            <name>repo</name>
            <releases>
                <enabled>true</enabled>
                <checksumPolicy>ignore</checksumPolicy>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <url>file://${project.basedir}/repo</url>
        </repository>
    </repositories>
    
    <dependencies>
        <!-- Leaving out irrelevant dependencies for brevity ... -->
        <dependency>
            <groupId>com.esi.cx</groupId>
            <artifactId>cx-utility</artifactId>
            <version>1.0.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    
    <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/xsd/maven-4.0.0.xsd">
    
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.esi.cx</groupId>
    <artifactId>cx-utility</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    
    <properties>
        <java.version>1.7</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    
    <dependencies>
        <!-- Leaving out irrelevant dependencies for brevity ... -->
    </dependencies>
    
    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.3</version>
                    <configuration>
                        <source>${java.version}</source>
                        <target>${java.version}</target>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
    
    
    4.0.0
    com.esi.cx
    cx实用程序
    1.0.0-SNAPSHOT
    1.7
    UTF-8
    org.apache.maven.plugins
    maven编译器插件
    3.3
    ${java.version}
    ${java.version}
    

    您能否在问题中添加更多细节。例如,您可以向我们展示cx配置服务的pom.xml吗?我认为必须添加LibA和LibB类依赖项,而不是module如果项目坐标(groupId、artifactId、version)与依赖项匹配,clipse会自动使用项目链接而不是JAR。这通常是您想要的方法,就好像您修改了库项目的一个类,依赖它的另一个项目将自动“看到”更改谢谢各位,我添加了我的POM作为参考。您可以在您的问题中添加更多详细信息吗。例如,您可以向我们展示cx配置服务的pom.xml吗?我认为必须添加LibA和LibB类依赖项,而不是module如果项目坐标(groupId、artifactId、version)与依赖项匹配,clipse会自动使用项目链接而不是JAR。这通常是您想要的方法,就像您修改了库项目的一个类一样,依赖它的另一个项目将自动“看到”更改谢谢各位,我添加了我的POM以供参考。