spring boot with no main class

mmaceachran :

I am trying use Spring Boot, and create a jar, and install it into my maven repo.

This is a library jar file that will be used as a dependency in my main application, which is also a Spring-Boot application. Right now, I am just working on a hello world example. here is my one class in this project:

public class MyLibrary {

  public String getMessage() {
    return "Hello World!";
  }
}

and my POM basically looks like this:

<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<groupId>com.me.plugin</groupId>
<artifactId>myLibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.7.RELEASE</version>
</parent>

<dependencies> 
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
</dependencies>

But when I try to build, I get 'Unable to find main class" error. Which makes perfect sense to me, but how do I get spring to make a library jar. I know I could add an Application.java with a main method, but that's not what I want, I want a simple jar file, but with all the Spring-Boot annotations, injections, etc...

How would I go about doing this? Is spring boot not what I want here?

surya :

I am sure you are using spring-boot-maven-plugin in your pom.xml (as given below), which allows you to package executable jar or war archives and run an application.

With this plugin, spring searches for a main application.You don't need this plugin for a spring library project. Delete this plugin and clean install .

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

I assume you are creating some spring configuration files or components in this library project. You may not need big fat spring-boot-starter. But its fine if you need multiple spring modules and you want one place for all dependency.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=433720&siteId=1