java - 如何在 Maven 构建中包含随机文件,以便在 AWS EBS 上部署 WAR 文件?
问题描述
我找到了这个答案https://serverfault.com/a/822596/123651
我需要\.ebextensions\nginx\conf.d\elasticbeanstalk\force-https.conf
在我的 WAR 中包含一个随机文件以部署在 AWS ElasticBeanstalk 控制台上。如何在mvn package
命令中包含此文件?ElasticBeanstalk 将如何在 WAR 中读取此文件?
我尝试使用本指南并添加到我的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
但它把文件放在错误的地方!
-rw-rw-r-- 0 0 0 94 Nov 14 12:40 WEB-INF/classes/force-https.conf
解决方案
这行得通。仅制作 2 个文件的 ZIP 似乎过于冗长。
pom.xml
<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>
并且配置文件就在项目根目录下。我不知道该放在哪里——它不是源代码。
force-ssl.conf
if ($http_x_forwarded_proto = 'http') {
return 301 https://$host$request_uri;
}
http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
推荐阅读
- api - 告诉 Ansible 迭代一个大型(网络摄像机)配置 yml 并通过一次 api 调用同时更新 100 个值
- r - 具有重复 id/时间观察的 plm 面板回归错误
- c# - Excelfile 到 DataGridview 与 ClosedXML
- amazon-web-services - 未使用 terraform import 导入策略
- javascript - Angular RouterLink 在新选项卡中运行
- ruby - 通过 Ruby 处理 vim 选择并替换内容
- java - 为特殊模块构建具有特殊配置文件的多模块项目
- python - condaEnviromentError: 无法删除当前环境。停用并再次运行 conda remove
- angular - 活动时 CSS 未应用于链接
- visual-studio - VS 2019 - 从 Microsoft.CodeAnalysis.CSharp.Analyzers 看到许多警告 AD0001