Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a library jar using Spring boot

I created a spring boot application having REST web services and jpa dependencies. The application runs on its own as a standalone application. I'm trying to add UI layer using vaadin as a separate project that uses the services from the sring boot project. Is there an easy way to make the spring boot application as a library jar that can be included in other projects.

I searched the forum and found some threads that advised not using spring boot but instead using the spring framework to create the library. Just wanted to check if there are any examples how this can be done in Spring boot.

like image 711
vijayanand Avatar asked Feb 23 '16 22:02

vijayanand


People also ask

How do you add a jar to Spring Boot?

There are two simple ways to do that: the simplest one is to add the property on the command line. Also, you will not launch the Spring Boot application in the usual format (java -jar application). On the other hand, you will launch the PropertiesLauncher class but adding in the classpath your Spring Boot application.


2 Answers

If your intention was to let Vaadin call the REST API you've created from the browser (as is usually the case with client-side frameworks like AngularJS), then you're misunderstanding Vaadin. A Vaadin application runs server-side.

So what you can do is run two servers, one running the Vaadin application and which calls the second one running your REST API. But if there's no need for this split, you can use the classes that form the REST API as a regular Java API called directly from the Vaadin application code.

like image 175
herman Avatar answered Oct 18 '22 03:10

herman


This project of mine may be of some interest to you. I have used Spring-Boot to make a library to be used in other projects.

The main thing to note here is to have:

@SpringBootApplication(scanBasePackages = {"me.ramswaroop.jbot", "example.jbot"})

in the main class where you start the spring-boot application. See this main class to learn more. But to be honest, using Spring-Boot to make a library to be included in other projects isn't a good choice according to me. If I were to rewrite JBot then I wouldn't have used Spring-Boot this way surely.

Spring-Boot is really good to create a stand-alone application that you can "just run" but to create a library, hmm, not sure. I think a library should have fewer dependencies as possible.

like image 1
Ram Patra Avatar answered Oct 18 '22 02:10

Ram Patra