简体   繁体   English

如何将java库连接到项目以测试库

[英]how to connect java library to project to test the library

So I need to connect a library to my repo in IntelliJ, so I can test the library as it interacts with my main project.所以我需要将一个库连接到我在 IntelliJ 中的存储库,以便我可以在它与我的主项目交互时测试该库。 And I got this command from a member on my team: "So you need to change .java files in entity manager (which is the library) repo and do mvn clean package to generate the jar file locally, the use that jar in your project repo. Then create dummy folder in your project with the same package name and copy those .java files from entity manager."我从我团队的一个成员那里得到了这个命令:“所以你需要在实体管理器(这是库)repo 中更改 .java 文件并执行 mvn clean package 以在本地生成 jar 文件,在你的项目中使用该 jar回购。然后在您的项目中创建具有相同包名的虚拟文件夹,并从实体管理器中复制那些 .java 文件。”

What does change the java files mean?更改java文件是什么意思? What about "use that jar"? “使用那个罐子”怎么样? I'm so confused.我很困惑。

Use "mvn install" instead of package.使用“mvn install”而不是包。 This puts the library into your local .m2 repo and makes it available to your project in idea这会将库放入您本地的 .m2 存储库中,并使其可用于您的项目中

If you do mvn clean package it produces a .jar file in target/ folder.如果您执行mvn clean package它会在 target/ 文件夹中生成一个 .jar 文件。 Use that dependency to your project if they both share a common parent pom.xml如果它们共享一个共同的父 pom.xml,则将该依赖项用于您的项目

If you do mvn clean install it produces the jar file in target/ folder + copies the .jar file to your local m2 folder.如果您执行mvn clean install它会在 target/ 文件夹中生成 jar 文件 + 将 .jar 文件复制到您的本地 m2 文件夹。 That way you can use that .jar file to any project locally.这样您就可以将该 .jar 文件用于本地的任何项目。 Just use the with matching version, artifact and groupId whereever you need to use that jar file.只需在需要使用该 jar 文件的任何地方使用匹配的版本、工件和 groupId。

For both options above, you need to define sth like below in your pom.xml对于上面的两个选项,您需要在 pom.xml 中定义如下内容

 <dependency>
        <groupId>com.my.library</groupId>
        <artifactId>mylib-artifact</artifactId>
        <version>1.VERSION</version>
</dependency>

Not recommended:不建议:

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

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