tomcat7-maven-plugin - 在 pom.xml 之外存储服务器 url [英] tomcat7-maven-plugin - store server url outside of pom.xml

查看:76
本文介绍了tomcat7-maven-plugin - 在 pom.xml 之外存储服务器 url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从事一些开源项目,不希望将生产服务器的 URL 保留在带有源代码的公共存储库中,但同时我希望有机会使用 tomcat-maven 进行部署-插件.

I'm working on some open-source project and wouldn't like to keep URL of production servers in public repository with source code, but at the same time I'd like to have an opportunity to deploy using tomcat-maven-plugin.

我尝试将服务器 url 从 pom.xml 移动到 settings.xml,但没有成功.你能不能给我一个提示,让 url 远离 pom.xml 的最佳方法是什么?

I tried to move server url from pom.xml to settings.xml, but it didn't work. Could You please give me a hint, what is the best way to keep url out of pom.xml?

非常感谢.

这是我的配置:设置.xml

Here is my configuration: settings.xml

<settings>
    <servers>
        <server>
            <id>prod</id>
            <username>deployer</username>
            <password>********</password>
        </server>
    </servers>
</settings>

pom.xml(在项目中)

pom.xml (in the project)

<project>
    ...
    <profiles>
        <profile>
            <id>prod</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <version>2.2</version>
                        <configuration>
                            <server>prod</server>
                            <url>http://host:XXXX/manager/text</url>
                            <path>/</path>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

更新:是的,有机会将其保存在 .properties-files 中,但是:

Update: Yes, there is an opportunity to keep this in .properties-files, but:

  1. 在几个地方保存服务器配置有点奇怪,即~/.m2/settings.xml、application.properties、pom.xml.只要用户名和密码能够存储在 settings.xml 中,最好将服务器 URL 也保留在那里.
  2. 实际上我无法让它工作,所以我一直在努力解决这个问题......

更新 2: 刚刚发现,为什么具有读取属性的方法对我不起作用.我用过:

Update 2: Just found out, why the approach with reading properties didn't work for me. I used:

mvn tomcat7:redeploy

部署应用程序,并且 properties-maven-plugin 没有在 tomcat7-maven-plugin 配置中的占位符中注入属性.由于 deploy 阶段,我更改了 tomcat7-maven-plugin 执行后,然后通过调用正常注入属性:

to deploy application, and properties-maven-plugin didn't inject properties in the placeholders in tomcat7-maven-plugin configuration. After I changed tomcat7-maven-plugin execution due to deploy phase, then the injection of properties works properly by invocation:

mvn clean deploy

但无论如何,我想知道,是否可以将服务器 URL 保留在 settings.xml 中?

But never the less, I would like to know, is it possible to keep server URL in settings.xml?

推荐答案

根据 规范.

您可以做的是在命令行上将服务器名称设置为参数:

What you could do is set the server name on the command line as a parameter:

mvn clean tomcat7:deploy -Drelease.server="http://host:XXXX"

在 pom.xml 中你可以像这样引用参数

And in pom.xml you can refer to the parameter like this

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <update>true</update>
                <url>${release.server}/manager/text</url>
                <server>MyServer</server>
                <path>/</path>
            </configuration>
        </plugin>

这篇关于tomcat7-maven-plugin - 在 pom.xml 之外存储服务器 url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆