Spring Boot and ebextensions

…衆ロ難τιáo~ 提交于 2020-01-02 03:10:53

问题


I'm trying to add an .ebextensions folder to the root level of my jar to be deployed to AWS elastic beanstalk.

My folder structure is:

main:
--src
--resources
  --.ebextensions

When I build the jar my .ebextensions gets placed on the classpath of my target and therefore is not picked up by Elastic Beanstalk on deploy.

Pom.xml

<plugin>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-maven-plugin</artifactId>
     <configuration>
           <fork>true</fork>
           <addResources>false</addResources>
     </configuration>
</plugin>

How can I build so that ebextensions is picked up by ELB?


回答1:


This works for me, is the cleanest way (in maven) I found to solve this:

Add .ebextensions in the root of your project and add this snippet at the end in the plugins section:

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.6</version>
            <executions>
                <execution>
                    <id>prepare</id>
                    <phase>package</phase>
                    <configuration>
                        <tasks>
                            <unzip src="${project.build.directory}/${project.build.finalName}.jar" dest="${project.build.directory}/${project.build.finalName}" />
                            <copy todir="${project.build.directory}/${project.build.finalName}/" overwrite="false">
                                <fileset dir="./" includes=".ebextensions/**"/>
                            </copy>
                            <zip compress="false" destfile="${project.build.directory}/${project.build.finalName}.jar" basedir="${project.build.directory}/${project.build.finalName}"/>
                        </tasks>
                    </configuration>
                    <goals>
                        <goal>run</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

This plugin use ant to unzip the final jar generated by spring boot, copy the .ebextensions in the root and zip (jar) again with the same name. Tested and working in production :)

Works with Spring 1.5.3.RELEASE




回答2:


I was having the same problems, moving .ebextensions next to the jar as Andy suggested worked for me when I combined it with directly adding a .conf file to the desired directory as suggested here:

https://stackoverflow.com/a/41011160/7686379



来源:https://stackoverflow.com/questions/42702947/spring-boot-and-ebextensions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!