简体   繁体   English

将一个 Maven 项目用于另一个 Maven 项目

[英]using one maven project into another maven project

I have two maven projects,我有两个 Maven 项目,

  1. testmvn测试虚拟机
  2. mvnusedemo mvnusedemo

testmvn: testmvn:

    <groupId>com.avs</groupId>
    <artifactId>testmvn</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>testmvn</name>

mvnusedemo: mvnusedemo:

    <groupId>com.avs</groupId>
    <artifactId>mvnusedemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>mvnusedemo</name>

now I have a class in project testmvn现在我在testmvn项目中有一个课程

package com.avs.Calculation;

public class AddNumbersME {
    public int addNumbers(int a, int b) {
        return a + b;
    }

    public int addNumbers(int a, int b, int c) {
        return a + b + c;
    }

}

i have run mvn install cmd, I got Build Success.我已经运行mvn install cmd,我得到了构建成功。 In the local repo(.m2) I can see those jars在本地 repo(.m2) 我可以看到那些罐子

Now I am trying to use this class(AddNumbersME) in project mvnusedemo现在我正在尝试在项目mvnusedemo 中使用这个类(AddNumbersME)

  1. Added dependency in pom.xml of mvnusedemomvnusedemo 的pom.xml 中添加依赖
<dependency>
    <groupId>com.avs</groupId>
    <artifactId>testmvn</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>

Now I can see the dependency added to the maven dependency folder in eclipse.现在我可以在eclipse中看到添加到maven依赖文件夹的依赖了。

  1. Now trying to use the **AddNumbersME **现在尝试使用 **AddNumbersME **
    public static void main(String[] args) {
        SpringApplication.run(MvnusedemoApplication.class, args);
        AddNumbersME a = new AddNumbersME(); // getting error - could not resolve 
    }

error: AddNumbersME cannot be resolved to a typeJava错误: AddNumbersME 无法解析为 typeJava

need help, do I am missing something ??需要帮助,我是不是遗漏了什么??

one of my friends helped me out, need to provide executions inside build -> plugin in pom.xml it looks like我的一位朋友帮助了我,需要在构建中提供执行 - > pom.xml 中的插件它看起来像

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <id>repackage</id>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>exec</classifier>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

now it is working fine.现在它工作正常。

You have the same group id in two of the projects.您在两个项目中具有相同的组 ID。 So use only import Calculation.AddNumbersME Don't add com.avs!所以只使用 import Calculation.AddNumbersME 不要添加 com.avs! Another suggestion: don't use uppercase package names such as Calculation.另一个建议:不要使用大写的包名,例如 Calculation。 Use lower case calculation as the package name!使用小写计算作为包名!

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

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