![](/img/trans.png)
[英]How do I include a random file in a Maven build for a WAR file to be deployed on AWS EBS?
[英]How do I include maven environment variables in eclipse to war file
我的 application.properties 中有環境變量,例如spring.mail.username=${username}
${username}
在 eclipse 環境變量中聲明。 當我構建 maven 包並安裝時,然后將其部署到 tcServer。 TC 服務器不知道${username}
。 換句話說,環境變量在構建過程中不包含在 war 文件中。
如何在 Eclipse 中獲取環境變量以包含在用於部署的 war 文件中?
如果您希望替換構建時變量,我建議您使用 maven 過濾:
有一個環境變量(不是日食):
export username=user3184890
然后,在您的 pom.xml 中,激活對資源的maven 過濾(假設您的 application.properties 在src/main/resources
:
<build>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
另外,將您的 application.properties 更改為:
spring.mail.username=${env.username}
或者
spring.mail.username=@env.username@
使用 alexbt's answer 中描述的 Maven 過濾是包含其他地方定義的值的正確方法。 他的示例涉及包含操作系統環境變量。 您也可以將其擴展到 Maven 屬性。 例如,
<project ...>
<properties>
<spring.mailuser>bob@mycompany.com</spring.mailuser>
</properties>
...
<build>
...
</build>
</project>
定義一個 Maven 屬性,其值由${spring.mailuser}
檢索,可以用作其他 Maven 配置的一部分或通過 Maven 過濾作為內容注入。 鑒於此,更改applicable.properties
如下
spring.mail.username=${spring.mailuser}
將在構建時注入屬性的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.