【问题标题】:Spring Maven generate two wars windows and unix same applicationSpring Maven 生成两个战争窗口和 unix 相同的应用程序
【发布时间】:2018-01-30 14:32:03
【问题描述】:

我有这样的应用程序上下文,适用于 windows

    <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">

<import resource="file:C:/test/applicationContext.xml" />
</beans>

对于 unix 来说应该是一样的,而不是 C: 有 opt。

我的目标是

“mvn -clean 包”

要生成两个war文件,例如myapp-windows.war和myapp-linux.war。

myapp-windows.war 应该具有带有 C:/test 的 windows 应用程序上下文。

myapp-unix.war 应该有 unix applicationContext 和 opt/test/。

我应该如何设置 applicationContext 来完成这项工作。

【问题讨论】:

  • 如果你想让你的配置外部化,最好有一个文件的相对路径。如果您仍想使用绝对路径,您可以使用带有 resource filtering 的 maven 配置文件来根据所使用的配置文件获得不同的文件输出。
  • @XtremeBiker 我尝试为 windows 和 unix 创建单独的资源,也在 maven 中创建了 2 个配置文件,但是当我运行 clean 并安装时只编译了 1 个配置文件并生成了 1 个战争
  • 您需要运行两次全新安装,每个要使用的配置文件一次。如果您想一步完成,只需编写一个简单的脚本即可。
  • @XtremeBiker 有 -P windows,unix in maven 解决了我的问题

标签: xml spring maven unix tomcat


【解决方案1】:

我不确定这是否对您有帮助,但我想您可以使用profiler 来执行此操作。它不会同时生成两个战争,但您可以根据操作系统系列配置设置,并将根据您正在运行的操作系统生成战争。

<profile>
    <id>platform-windows</id>
    <activation>
        <os>
            <family>windows</family>
        </os>
    </activation>
    <build>
        <plugins>
            ...
        </plugins>
    </build>
</profile>

【讨论】:

  • 我试过这需要两次运行来生成两者,也试过 mvn package -P platform-windows,platform-unix 但它总是运行 pom 中的最后一个配置文件,而不是两个
  • 这将根据运行构建的操作系统激活配置文件,而不是运行战争的目标系统..
猜你喜欢
  • 2017-12-21
  • 1970-01-01
  • 2014-12-31
  • 2016-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-16
  • 1970-01-01
相关资源
最近更新 更多