简体   繁体   中英

Access Classes and API from jar which is also inside another jar

I have developed three separate Spring boot projects

  • authentication

  • authorization

  • platform(Main Project)

My main project requires the jar of both authentication and authorization projects.

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.

Now because authentication is already in the classpath of platform(Main Project) , so I believe that authorization should also be present.

But in platform(Main Project) I am unable to access the classes of authorization .

Authentication's pom.xml

身份验证 POM XML

Platform(Main Project)'s 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.

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.

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
  • or required jar hasn't been properly added to the classpath.

make sure that the jar has been properly installed in .m2 folder, for the second step

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.

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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