简体   繁体   English

使用 tomcat-maven-plugin 部署预构建的 WAR

[英]Deploying prebuilt WAR with tomcat-maven-plugin

I have a WAR file properly generated by Warbler and it's working when I do this all by hand.我有一个由 Warbler 正确生成的 WAR 文件,当我手动完成所有操作时它就可以工作。

I'm trying to use maven (via Hudson) to我正在尝试使用 maven (通过哈德逊)

1) Invoke the warble (successful) 1)调用warble(成功)

<phase>package</phase>
<configuration>
    <executable>/bin/bash</executable>
    <workingDirectory>.</workingDirectory>
    <arguments>
        <argument>-c</argument>
        <argument>
            echo "Sourcing bashrc"
            source ~/.bashrc
            rvm use jruby
            echo "Path is $PATH"
            echo "Gem path is $GEM_PATH"
            warble --trace
            rm -R target/*
            mv workspace.war target/yams.war
        </argument>
    </arguments>
</configuration>

2) deploy to tomcat 2)部署到tomcat

It's part two that I'm having trouble with.这是我遇到麻烦的第二部分。 I want to just tell maven to take the WAR file I just generated (and helpfully moved to target/, as it expects) and deploy it.我只想告诉 maven 获取我刚刚生成的 WAR 文件(并有助于移动到 target/,正如它所期望的那样)并部署它。

The problem is, if I don't specify a packaging for the whole project, it just skips any deploy ("skipping non-WAR").问题是,如果我没有为整个项目指定打包,它只会跳过任何部署(“跳过非 WAR”)。 If I specify WAR packaging, it tries to make a useless WAR itself, which would be okay but it keeps asking for more and more information (webxml, etc) to make this useless WAR which I'd just end up deleting and ignoring anyways.如果我指定 WAR 打包,它会尝试自己制作一个无用的 WAR,这没关系,但它会不断要求越来越多的信息(webxml 等)来制作这个无用的 WAR,我最终还是会删除并忽略它。

Basically, is there a simple way to say "take the war I just created in workspace/target/ and deploy it as you would any WAR you made yourself" to maven?基本上,有没有一种简单的方法可以说“将我刚刚在工作区/目标/中创建的战争并将其部署为您自己制作的任何 WAR”到 maven?

First ever post:)第一次发帖:)

Yes, it is possible.对的,这是可能的。 The trick is to disable the execution of the maven-war-plugin so that it doesn't try to package anything.诀窍是禁用 maven-war-plugin 的执行,这样它就不会尝试 package 任何东西。 Then you can simply point the tomcat at the pre-build war you've already assembled.然后,您可以简单地将 tomcat 指向您已经组装的预构建战争。 Here's my POM which deploys the prebuild lambda Probe WAR file:这是我的 POM,它部署了预构建 lambda Probe WAR 文件:

<project>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>Probe</artifactId>
    <packaging>war</packaging>

    <name>Probe</name>  

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.1.1</version>
                <executions>
                    <execution>
                        <id>default-war</id>
                        <phase>none</phase>
                    </execution>
                </executions>                    
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>tomcat-maven-plugin</artifactId>
                <configuration>
                    <warFile>Probe.war</warFile>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Thanks to waffel's Weblog for providing me with the generic solution that led me to figuring out how to disable execution of the maven-war-plugin.感谢waffel 的博客为我提供了通用解决方案,使我弄清楚如何禁用 maven-war-plugin 的执行。 :) :)

*edit: you may also want to disable the maven-install-plugin to keep maven from complaining when you invoke the oft-used 'mvn clean install' (message looks like this:) *编辑:您可能还想禁用 maven-install-plugin 以防止 maven 在您调用常用的“mvn clean install”时抱怨(消息如下所示:)

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install (default-install) on project: The packaging for this project did not assign a file to the build artifact [错误] 无法在项目上执行目标 org.apache.maven.plugins:maven-install-plugin:2.3.1:install (default-install):此项目的打包未将文件分配给构建工件

Add this section to your POM:将此部分添加到您的 POM:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-install-plugin</artifactId>
            <version>2.3.1</version>
            <executions>
                <execution>
                    <id>default-install</id>
                    <phase>none</phase>
                </execution>
            </executions>
        </plugin>

If you want your project to actually install the war file into your repository, I think you'll be stuck with using the maven-install-plugin's install:install-file goal.如果您希望您的项目将战争文件实际安装到您的存储库中,我认为您将无法使用 maven-install-plugin 的 install:install-file 目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM