嗨 Spring 季启动专家 -
我正在尝试创建一个需要部署到apache风暴集群的spring boot uber jar . 但是,问题在于,当使用“spring-boot-maven-plugin”打包时,Storm正在期望jar的根目录中的所有类文件,而打包的app文件在“BOOT-INF / classes”下 .
有没有办法让我的应用程序类直接打包在根目录下而不是“BOOT-INF / classes”?
我尝试使用“maven-assembly-plugin”和“spring-boot-maven-plugin”,如下所示,它创建了Uber jar,包含来自uber jar根目录的依赖jar中的所有类文件,但是app类仍然在BOOT-INF / classes .
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.apache.storm</groupId>
<artifactId>storm-core</artifactId>
</exclude>
</excludes>
<requiresUnpack>
<dependency>
<groupId>com.myorg</groupId>
<artifactId>my-app-artifact</artifactId> <!-- This does not help! :( -->
</dependency>
</requiresUnpack>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<appendAssemblyId>false</appendAssemblyId>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
2 回答
因此,对于我未来的自我或任何试图找到类似问题答案的人 . 以下是我在研究过程中发现的不同事物 -
Storm需要一个可执行的java jar文件
Spring Boot提供自定义jar包装 . 虽然它通过java jar包装确认,但Spring Boot从BOOT-INF / classes加载类
因此,为了使Spring Boot jar在Storm群集上工作,同时表现为Spring Boot - 我们需要创建从BOOT-INF / classes到jar文件根目录的所有类的副本 .
这可能吗?答案是肯定的 .
使用描述here的方法,我能够创建一个Spring Boot jar,其中BOOT-INF /类被复制到Spring Boot jar的根目录 . 这种方法需要ant build.xml,常 Spring 藤设置和ivy.xml,如下所示 . (免责声明:配置仅测试直到风暴群集上没有包装)
因为我们能够在根目录下创建一个被类攻击的Spring Boot Jar -
Should we do it? NO .
原因如下 -
Spring强烈建议不要采用这种方法,以免在jar文件和不同版本中具有相同名称的类的不必要的类重写和类版本控制问题 .
Spring Boot Jar包装不是用作依赖jar的格式 . Read the first line here.因此,对于依赖用例,您需要坚持使用普通的旧Java模块 . Spring Boot适用于更多独立的可执行文件或部署在像tomcat这样的容器上 .
祝好运!
build.xml
ivysettings.xml
ivy.xml
是的,你只需要使用Spring Boot 1.3 . 如果你像这样声明你的父母,请回到你的pom.xml中的maven ...:
那么你的类(和其他文件)将放在根级别 . 这是 Spring 季靴子的“旧方式” .
在1.4版本中,他们将spring boot jar结构更改为使用BOOT-INF目录 . 因此,如果您使用
<version>1.4.1.RELEASE</version>
,那么您的类将在BOOT-INF / classes下 . 不良副作用是您的配置文件(例如,application.properties,application-myprofile.properties等)也将位于BOOT-INF /类下,即使它们不是Java类 .