【问题标题】:Using placeholders in Jetty contextXML file在 Jetty contextXML 文件中使用占位符
【发布时间】:2020-04-19 00:21:48
【问题描述】:

我正在使用 Maven 和 jetty 插件在本地启动我的应用程序。 而且我已经看到了可以在 Jetty contextXML 中使用占位符的方法。 这是我连接码头插件的 pom.xml 的一部分(位于单独的模块中):

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <configuration>
        <stopKey>${test.jetty.stop-key}</stopKey>
        <stopPort>${test.jetty.stop-port}</stopPort>
        <webAppConfig>
            <contextPath>/${test.contextPath}/*</contextPath>
        </webAppConfig>
        <httpConnector>
            <port>${jetty.port}</port>
            <host>${jetty.host}</host>
        </httpConnector>
        <contextXml>${project.basedir}/src/main/resources/jetty/${jetty.mode}-jetty.xml</contextXml>
    </configuration>
<dependencies>
...
</dependencies>
</plugin>

这是我的 stub-jetty.xml 文件的一部分:

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
...
<New id="loggerCF" class="org.eclipse.jetty.plus.jndi.Resource">
    <Arg></Arg>
    <Arg>jms/logger/connectionFactory/loggerCF</Arg>
    <Arg>
        <New class="org.apache.activemq.ActiveMQConnectionFactory">
            <Arg>tcp://${active-mq.host}:${active-mq.port}</Arg>
        </New>
    </Arg>
</New>
</Configure>

ma​​in pom.xml 文件中定义的参数“active-mq.host”和“active-mq.port”。

当我运行时,我收到下一个异常:

Caused by: java.net.URISyntaxException: Illegal character in authority at index 6: tcp://${active-mq.host}:${active-mq.port}
    at java.net.URI$Parser.fail (URI.java:2848)
    ...

所以我知道 Jetty 不明白需要将占位符更改为 Maven 属性中的值。如何解决这个问题或我能读到什么?

【问题讨论】:

    标签: maven jetty


    【解决方案1】:

    您不能直接引用Maven 配置中定义的属性。使用System Properties 可以实现所需的行为。您可以将其设置为jetty-maven-pluginconfiguration 的一部分,所需选项为systemPropertiessystemPropertiesFile

    这是一个粗略的例子(请注意,我没有检查过):

    <New class="org.apache.activemq.ActiveMQConnectionFactory">
        <Arg>tcp://<SystemProperty name="active-mq.host"/>:<SystemProperty name="active-mq.port"/></Arg>
    </New>
    

    pom:

    <plugin>
       <groupId>org.eclipse.jetty</groupId>
       <artifactId>maven-jetty-plugin</artifactId>
       <configuration>
            <systemProperties>
                <systemProperty>
                    <name>active-mq.host</name>
                    <value>${active-mq.host}</value>
                </systemProperty>
                <systemProperty>
                    <name>active-mq.port</name>
                    <value>${active-mq.port}</value>
                </systemProperty>
            </systemProperties>
        </configuration>
    </plugin>
    

    【讨论】:

    • 感谢您的回复!我知道在插件配置区域中使用 systemProperty 的这种方式。但是在某处我看到使用我在问题中描述的方法但仍然无法在 Google 中找到正确的示例:) 我将继续搜索...
    猜你喜欢
    • 2014-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-08-26
    • 2020-06-05
    • 1970-01-01
    • 2015-02-27
    • 2013-10-16
    • 2015-09-05
    相关资源
    最近更新 更多