如何在要在AWS EBS上部署的WAR文件的Maven构建中包括随机文件? [英] How do I include a random file in a Maven build for a WAR file to be deployed on AWS EBS?
问题描述
我找到了这个答案 https://serverfault.com/a/822596/123651
我需要在我的WAR中包括一个随机文件\.ebextensions\nginx\conf.d\elasticbeanstalk\force-https.conf
,以将其部署在AWS ElasticBeanstalk控制台上.如何在mvn package
命令中包含此文件? ElasticBeanstalk如何在WAR中读取此文件?
I need to include a random file \.ebextensions\nginx\conf.d\elasticbeanstalk\force-https.conf
in my WAR to be deployed on the AWS ElasticBeanstalk console. How do I include this file in the mvn package
command? How will ElasticBeanstalk read this file inside of the WAR?
我尝试使用此指南并添加到我的pom.xml
I tried to use this guide and added to my pom.xml
<build>
...
<resources>
<resource>
<directory>.ebextensions/nginx/conf.d/elasticbeanstalk/</directory>
<includes>
<include>force-https.conf</include>
</includes>
</resource>
</resources>
</build>
然后分别运行mvn package -DskipTests
和tar tvf target\app-0.0.3-SNAPSHOT.war | less
,但是它将文件放置在错误的位置!
Then ran mvn package -DskipTests
and tar tvf target\app-0.0.3-SNAPSHOT.war | less
but it put the file in the wrong place!
-rw-rw-r-- 0 0 0 94 Nov 14 12:40 WEB-INF/classes/force-https.conf
推荐答案
此方法有效.仅制作2个文件的ZIP文件似乎过于冗长.
This worked. It seems excessively verbose for just making a ZIP of 2 files.
<plugin> <!-- To add .ebextensions/ Nginx config for ElasticBeanstalk -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
assembly.xml
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>bin</id>
<baseDirectory>/</baseDirectory>
<formats>
<format>zip</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<outputDirectory>/</outputDirectory>
<includes>
<include>*-SNAPSHOT.war</include>
</includes>
</fileSet>
<fileSet>
<directory>${project.basedir}</directory>
<outputDirectory>/.ebextensions/nginx/conf.d/elasticbeanstalk/</outputDirectory>
<includes>
<include>force-https.conf</include>
</includes>
</fileSet>
</fileSets>
</assembly>
并且配置文件仅在项目根目录中.我不知道该把它放在哪里-它不是源代码.
And the configuration file is just in the project root. I didn't know where else to put it - it's not source code.
if ($http_x_forwarded_proto = 'http') {
return 301 https://$host$request_uri;
}
http://maven.apache.org/plugins/maven -assembly-plugin/assembly.html
这篇关于如何在要在AWS EBS上部署的WAR文件的Maven构建中包括随机文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!