一尘不染

如何在Maven构建中包括一个随机文件,以将WAR文件部署在AWS EBS上?

tomcat

我找到了这个答案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 -DskipTeststar 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

阅读 202

收藏
2020-06-16

共1个答案

一尘不染

这工作了。仅制作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

2020-06-16