首页 文章

Maven Tomcat使用配置文件部署插件

提问于
浏览
1

我试图在我的项目pom.xml文件中使用配置文件来控制我的war文件到特定服务器的部署 . 例如,我有一个本地配置文件和一个开发服务器配置文件 . 这是我如何设置我的配置文件

<profiles>

    <profile>
        <id>local</id>
        <activation>
            <activeByDefault>true</activeByDefault>
            <property>
                <name>target</name>
                <value>local</value>
            </property>
        </activation>
        ...
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <url>http://10.16.21.60:8080/manager/text</url>
                        <server>localTomcat</server>
                        <path>/</path>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

    <profile>
        <id>dev</id>
        <activation>
            <property>
                <name>target</name>
                <value>dev</value>
            </property>
        </activation>
        ...
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.2</version>
                    <configuration>
                        <url>http://devserverurl:8080/manager/text</url>
                        <server>devTomcat</server>
                        <path>/</path>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </profile>

我在打电话

mvn org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy

当我尝试这个时,我可以看到,而不是尝试连接到我的配置 10.16.21.60 中提供的IP地址,而是尝试连接到 localhost . 我在本地 settings.xml 文件中使用用户名和密码定义了 devTomcatlocalTomcat .

如果我然后添加 -X 选项以获取更多信息,我可以在插件的调试输出中看到( emphasis added

[DEBUG] Configuring mojo org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy from plugin realm ClassRealm[plugin>org.apache.tomcat.maven:tomcat7-maven-plugin:2.2, parent: sun.misc.Launcher$AppClassLoader@5c647e05]
    [DEBUG] Configuring mojo 'org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy' with basic configurator -->
    [DEBUG]   (f) charset = ISO-8859-1
    [DEBUG]   (f) contextFile = ....
    [DEBUG]   (f) ignorePackaging = false
    [DEBUG]   (f) mode = war
    [DEBUG]   (f) packaging = war
    [DEBUG]   (f) path = ...
    [DEBUG]   (f) update = false
    [DEBUG]   (f) url = http://localhost:8080/manager/text
    [DEBUG]   (f) version = 2.2
    [DEBUG]   (f) warFile =  ...
    [DEBUG]   (f) settings = org.apache.maven.execution.SettingsAdapter@61874b9d
    [DEBUG] -- end configuration --
    [INFO] Deploying war to http://localhost:8080/...  
    [DEBUG] No server specified for authentication - using defaults

似乎没有遵守我的配置设置!我认为这将起作用的方式是,因为 local 配置文件被激活,它将使用该配置 .

我也尝试简单地在我的 <build> 部分中定义插件,没有配置文件,具有相同的效果 . 它始终尝试连接到 http://localhost:8080 而不进行身份验证 .

值得注意的是,我也在使用 gwt-maven-plugin 这个项目,我不知道这是否会干扰tomcat插件配置 .

1 回答

  • 0

    好吧,事实证明我使用了错误的 groupID 插件 . 事实并非如此

    <groupId>org.codehaus.mojo</groupId>
    

    它是

    <groupId>org.apache.tomcat.maven</groupId>
    

    现在像一个冠军!

相关问题