繁体   English   中英

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

[英]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中读取此文件?

我试图使用本指南并将其添加到我的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 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM