简体   繁体   English

从 jar 访问类和 API,该 jar 也在另一个 jar 中

[英]Access Classes and API from jar which is also inside another jar

I have developed three separate Spring boot projects我开发了三个独立的 Spring boot 项目

  • authentication验证

  • authorization授权

  • platform(Main Project)平台(主要项目)

My main project requires the jar of both authentication and authorization projects.我的项目需要认证授权项目的jar。

But, There are some classes present in authorization project which is required by the authentication , so one way was copy all the required stuff and pasted into the authentication project which is not an ideal practice or solution .但是,授权项目中存在一些身份验证所需的类,因此一种方法是将所有必需的内容复制并粘贴到身份验证项目中,这不是理想的做法或解决方案 So what I did, I simply created the jar of authorization project and add the dependency in authentication's pom.xml.所以我所做的,我只是创建了授权项目的 jar 并在身份验证的 pom.xml 中添加了依赖项。

Now because authentication is already in the classpath of platform(Main Project) , so I believe that authorization should also be present.现在因为身份验证已经在platform(Main Project)的类路径中,所以我相信授权也应该存在。

But in platform(Main Project) I am unable to access the classes of authorization .但是在平台(主项目)中,我无法访问授权类。

Authentication's pom.xml认证的 pom.xml

身份验证 POM XML

Platform(Main Project)'s pom.xml平台(主项目)的 pom.xml

In below snapshot it is clearly depicted that I have commented out the authorization dependency because it moves out to the authentication .在下面的快照中,清楚地描述了我已经注释掉了授权依赖,因为它移出了身份验证 在此处输入图片说明

In below snapshot it is clearly depicted that I have commented out the authorization dependency because it moves out to the authentication .在下面的快照中,清楚地描述了我已经注释掉了授权依赖,因为它移出了身份验证

I am not able to figured it out why this is happening, kindly help, it would be really appreciated我无法弄清楚为什么会发生这种情况,请提供帮助,将不胜感激

Sounds quiet strange and interesting, because as you said that your authorization is already in the classpath of authentication and the same present in your main project.听起来很奇怪很有趣,因为正如您所说,您的authorization已经在authentication的类路径中,并且在您的主项目中也是如此。

Well if above is the case then it is pretty fine, nothing wrong in that, you should be able to access the api of your authorize project.好吧,如果上面是这种情况,那就很好了,没有错,您应该能够访问授权项目的 api。

But if not, then there are several reasons for the same, the most common are但如果不是,那么有几个相同的原因,最常见的是

  • Either the jar is not correctly installed in your .m2 folder jar 未正确安装在您的.m2文件夹中
  • or required jar hasn't been properly added to the classpath.或所需的 jar 尚未正确添加到类路径中。

make sure that the jar has been properly installed in .m2 folder, for the second step确保 jar 已正确安装在 .m2 文件夹中,用于第二步

please follow the below steps, it might be helpful for请按照以下步骤操作,它可能对您有所帮助

First, open External Dependencies In your IDE, and check whether your authorization dependency is present or not.首先,在你的IDE中打开External Dependencies,检查你的授权依赖是否存在。

If not, then perform maven clean install on your authentication project, that will create the jar inside target folder, after the jar has been created, check the pom xml of jar and check whether it contains the authorize project dependency or not?如果没有,则在您的身份验证项目上执行 maven clean install,这将在目标文件夹中创建 jar,在创建 jar 后,检查jar的 pom xml 并检查它是否包含授权项目依赖项?

AFAIK,Spring Boot JAR 不能用作依赖项。

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

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