3

i´m currently working on a Spring Boot jar library for reuseable components like

  • ldap
  • email
  • messaging with apache kafka
  • rest api usage

Aim:
Every Java "user/coder" of our company should be able to "put" this jar in ones project (by maven or whatever) and use the reusable components instead of coding all things by hand over and over again.

Building microservices for that issue over REST is not an alternative to us.

My question is:
Can i reuse this Spring Boot jar library in any plain Java projects?

Beeing fond, can i "put" this jar library into a Java project and wire my Spring Boot services from that library in my "non Spring Boot" vanilla Java project?

Notice / Edited:
I have used Spring Boot as project template (spring-boot-starter-parent).
I configure my templates like the LdapTemplate by hand and don´t let Spring Boot do the magic.

Edit
As far as the reuse in Spring Boot/Spring projects is concerned, everything is fine. I´ve done that already.

My aim with that library may be that every Java "user" can use this library, like so:
final SuperCoolLibary scl = new SuperCoolLibrary(); final boolean exists = scl.searchForLdapUser("tlang");

So another question maybe:
Would it be better do switch this library to maybe the new Java Jigsaw module infrastructure?

3
  • It depends. Do you use spring or spring boot feature in the library ? Commented Apr 8, 2019 at 12:58
  • Yes you can put any spring boot jar or any java project into another java project, In case of Maven,you can add that project into pom.xml as dependency Commented Apr 8, 2019 at 12:59
  • thank you for your help. i have updated my question right now ... Commented Apr 8, 2019 at 13:21

1 Answer 1

5
  1. Write your own Spring-Boot-Auto-Starter. A guide can be found under: https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-developing-auto-configuration.html
  2. This way your library can be used in every spring boot project by just adding it as dependency (which means the jar must be in your classpath).
  3. If your Java Application does not use the SpringContext the services cannot be "wired" by spring into your plain vanilla java application.
Sign up to request clarification or add additional context in comments.

2 Comments

Hmm. As far as I understand your question the answer is: "Yes everyone can use your library as long as it is available on the classpath and provides a clear public API". With Jigsaw you'll be able to restrict or better said define more clearly what your "public API" of your library is. But generally said: they would be able to use your code. It's the same with all the other libraries you already used in your spring-boot projects ;-)
thanks again. i will try that out! maybe i can post a github link if the library is ready to let you know about it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.