java 没有主类的弹簧靴
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46877581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
spring boot with no main class
提问by mmaceachran
I am trying use Spring Boot, and create a jar, and install it into my maven repo.
我正在尝试使用 Spring Boot,并创建一个 jar,并将其安装到我的 maven 存储库中。
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:
这是一个库 jar 文件,将在我的主应用程序中用作依赖项,它也是一个 Spring-Boot 应用程序。现在,我只是在研究一个 hello world 示例。这是我在这个项目中的一个班级:
public class MyLibrary {
public String getMessage() {
return "Hello World!";
}
}
and my POM basically looks like this:
我的 POM 基本上是这样的:
<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...
但是当我尝试构建时,我收到“无法找到主类”错误。这对我来说很有意义,但是我如何让 spring 制作库 jar。我知道我可以使用 main 方法添加 Application.java ,但这不是我想要的,我想要一个简单的 jar 文件,但是包含所有 Spring-Boot 注释、注入等...
How would I go about doing this? Is spring boot not what I want here?
我该怎么做呢?弹簧靴不是我想要的吗?
回答by 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.
我确定您在 pom.xml 中使用 spring-boot-maven-plugin(如下所示),它允许您打包可执行的 jar 或 war 档案并运行应用程序。
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 .
使用此插件,spring 会搜索主应用程序。spring 库项目不需要此插件。删除此插件并全新安装。
<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.
我假设您正在这个库项目中创建一些 spring 配置文件或组件。您可能不需要大胖 spring-boot-starter。但是,如果您需要多个 spring 模块并且希望所有依赖项都在一个地方,那就没问题了。