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

发布于 2024-11-09 03:45:21 字数 1035 浏览 0 评论 0原文

我有一个由 Warbler 正确生成的 WAR 文件,当我手动完成这一切时,它正在工作。

我正在尝试使用maven(通过Hudson)来

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)部署到tomcat

这是我遇到问题的第二部分。我只想告诉 maven 获取我刚刚生成的 WAR 文件(并按预期移动到 target/)并部署它。

问题是,如果我没有为整个项目指定打包,它只会跳过任何部署(“跳过非 WAR”)。如果我指定 WAR 打包,它会尝试创建一个无用的 WAR 本身,这没什么问题,但它会不断要求提供越来越多的信息(webxml 等)来创建这个无用的 WAR,无论如何我最终都会删除并忽略它。

基本上,有没有一种简单的方法可以对maven说“将我刚刚在workspace/target/中创建的战争并将其部署为您自己创建的任何战争”?

I have a WAR file properly generated by Warbler and it's working when I do this all by hand.

I'm trying to use maven (via Hudson) to

1) Invoke the warble (successful)

<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

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.

The problem is, if I don't specify a packaging for the whole project, it just skips any deploy ("skipping non-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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若相惜即相离 2024-11-16 03:45:21

有史以来第一次发帖:)

是的,这是可能的。诀窍是禁用 maven-war-plugin 的执行,这样它就不会尝试打包任何东西。然后,您只需将 tomcat 指向您已经组装的预构建战争即可。这是我的 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>

感谢 waffel 的博客为我提供了通用解决方案,引导我弄清楚如何禁用 maven- 的执行战争插件。 :)

*编辑:您可能还想禁用 maven-install-plugin 以防止 maven 在调用常用的“mvn clean install”时发出抱怨(消息如下所示:)

[错误] 未能执行目标
org.apache.maven.plugins:maven-install-plugin:2.3.1:安装
项目上的(默认安装):此项目的包装
项目未将文件分配给构建工件

将此部分添加到您的 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>

如果您希望您的项目实际将 war 文件安装到您的存储库中,我认为您将不得不使用 maven-install-plugin 的 install:install - 文件目标。

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. Then you can simply point the tomcat at the pre-build war you've already assembled. Here's my POM which deploys the prebuild lambda Probe WAR file:

<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. :)

*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:)

[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

Add this section to your 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文