简体   繁体   English

使用 maven 从 nexus 访问部署的库

[英]Access deployed library from nexus using maven

I have a project structure as:我有一个项目结构:

projects
|
|
|  |
|  +--bom
|  |  |
|  |  +--pom.xml [The POM of bom:0.0.1-SNAPSHOT]
|  |
|  +--project1
|  |  |
|  |  +--pom.xml [The POM of project1:0.0.1-SNAPSHOT]
|  |
|  +--project2
|  |  |
|  |  +--pom.xml [The POM of project2:0.0.1-SNAPSHOT]

I have deployed a jar library of project 1 to nexus and trying to access it in project 2 pom as:我已经将项目 1 的 jar 库部署到 nexus 并尝试在项目 2 pom 中访问它:

project 2:项目2:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.10.RELEASE</version>
</parent>

<artifactId>project2</artifactId>

<packaging>war</packaging>

<dependency>
            <groupId>com.test</groupId>
            <artifactId>project1</artifactId>
            <version>0.0.1-SNAPSHOT</version>
</dependency>

POM of project1:项目1的POM:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.10.RELEASE</version>
    </parent>
    <groupId>com.test</groupId>
    <artifactId>project1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
<distributionManagement>

    <snapshotRepository>
        <id>deploy.snapshots</id>
        <url>
            <nexus server>
        </url>
    </snapshotRepository>
</distributionManagement>
<!-- Nexus Deployment -->

I can see the com.test.project1:0.0.1-SNAPSHOT under dependency tree of project2.我可以在 project2 的依赖树下看到 com.test.project1:0.0.1-SNAPSHOT。

But, as I am trying to access a class(enumtypes.Activation.java) of project1 in project2, I get error Error:(3,51) java: package com.test.enumtypes does not exist.但是,当我试图在 project2 中访问 project1 的一个类(enumtypes.Activation.java)时,我收到错误 Error:(3,51) java: package Z4D236D9A204D102C5FE6BAD1 不存在。

Not sure what could be the reason.不知道可能是什么原因。

As suggested by @ dunni there is a way to Use a Spring Boot Application as a Dependency.正如@dunni所建议的,有一种方法可以使用 Spring 引导应用程序作为依赖项。 Like a war file, a Spring Boot application is not intended to be used as a dependency.与 war 文件一样,Spring 引导应用程序不打算用作依赖项。 If your application contains classes that you want to share with other projects, the recommended approach is to move that code into a separate module.如果您的应用程序包含您想与其他项目共享的类,推荐的方法是将该代码移动到单独的模块中。 The separate module can then be depended upon by your application and other projects.然后,您的应用程序和其他项目可以依赖单独的模块。

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

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