【问题标题】:How do I include a random file in a Maven build for a WAR file to be deployed on AWS EBS?如何在 Maven 构建中包含随机文件以在 AWS EBS 上部署 WAR 文件?
【发布时间】:2019-04-17 18:02:16
【问题描述】:

我找到了这个答案https://serverfault.com/a/822596/123651

我需要在我的 WAR 中包含一个随机文件 \.ebextensions\nginx\conf.d\elasticbeanstalk\force-https.conf 以部署在 AWS ElasticBeanstalk 控制台上。如何在mvn package 命令中包含此文件? ElasticBeanstalk 将如何在 WAR 中读取此文件?

我尝试使用这个guide 并添加到我的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

【问题讨论】:

  • 文件应该放在哪里?根据 ServerFault 的回答,它应该在 ZIP 容器中,但在 WAR/JAR 文件之外。
  • @Compass 是的,这似乎有效。我手动创建了一个包含 WAR 和 .conf 的 zip 文件,它确实有效。那么如何使用 Maven 创建一个 zip 文件呢?现在正在查找...

标签: java amazon-web-services maven tomcat amazon-elastic-beanstalk


【解决方案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

【讨论】:

  • 不幸的是,这会破坏 Spring Boot 应用程序并导致正确路径的 404 错误。
猜你喜欢
  • 2011-03-18
  • 1970-01-01
  • 2012-08-22
  • 1970-01-01
  • 2014-08-20
  • 1970-01-01
  • 2016-06-17
  • 2018-11-15
  • 1970-01-01
相关资源
最近更新 更多