Maven 和 Cargo:使用 war-File 启动 Jetty-Container

发布于 2024-10-12 04:13:02 字数 2792 浏览 7 评论 0原文

我刚刚启动了一个新的 Maven 项目,该项目旨在启动一个包含来自依赖项目的 war 文件的 Jetty。货物插件应该是正确的工具。

不幸的是它对我不起作用。它成功启动了 Jetty,但它只包含 default-cargo-war-file,而不是预期的文件。

这是我的 war-File 的相关部分:

<dependencies>
   <dependency>
      <groupId>com.group</groupId>
      <artifactId>my-webapp</artifactId>
      <version>0.1.0-SNAPSHOT</version>
      <type>war</type>
   </dependency>    
</dependencies>

<build>     
    <plugins>                       
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.0.5</version>
            <configuration>
                <container>
                    <containerId>jetty7x</containerId>
                    <type>embedded</type>                       
                </container>
                <configuration>
                    <properties>
                        <cargo.servlet.port>7070</cargo.servlet.port>
                        <cargo.logging>high</cargo.logging>
                    </properties>
                </configuration>            
                <deployer>
                    <type>embedded</type>
                    <deployables>
                        <deployable>
                            <groupId>com.group</groupId>
                            <type>war</type>
                            <artifactId>my-webapp</artifactId>
                            <properties>
                                <context>/path</context>
                            </properties>
                        </deployable>                           
                    </deployables>
                </deployer>                 
            </configuration>                
        </plugin>
    </plugins>
</build>

我通过启动 mvn Cargo:start 来使用该插件。

没有错误日志输出。

[INFO] [cargo:start]
[INFO] [beddedLocalContainer] Jetty 7.x Embedded starting...
2011-01-17 18:57:44.586:INFO::jetty-7.2.0.v20101020
2011-01-17 18:57:44.663:INFO::Extract jar:file:/tmp/cargo/conf/cargocpc.war!/ to /tmp/jetty-0.0.0.0-7070-cargocpc.war-_cargocpc-any-/webapp
2011-01-17 18:57:45.082:INFO::Started [email protected]:7070
[INFO] [beddedLocalContainer] Jetty 7.x Embedded started on port [7070]

我如何告诉 Cargo 加载指定的 war 文件?

I just started a new Maven project that is intended to start a Jetty containing a war-File from a depended project. The cargo-plugin should be the right tool for this.

Unfortunately it doesn't work for me. It starts Jetty successfully but it only contains the default-cargo-war-file, not the expected one.

This is the relevant part of my war-File:

<dependencies>
   <dependency>
      <groupId>com.group</groupId>
      <artifactId>my-webapp</artifactId>
      <version>0.1.0-SNAPSHOT</version>
      <type>war</type>
   </dependency>    
</dependencies>

<build>     
    <plugins>                       
        <plugin>
            <groupId>org.codehaus.cargo</groupId>
            <artifactId>cargo-maven2-plugin</artifactId>
            <version>1.0.5</version>
            <configuration>
                <container>
                    <containerId>jetty7x</containerId>
                    <type>embedded</type>                       
                </container>
                <configuration>
                    <properties>
                        <cargo.servlet.port>7070</cargo.servlet.port>
                        <cargo.logging>high</cargo.logging>
                    </properties>
                </configuration>            
                <deployer>
                    <type>embedded</type>
                    <deployables>
                        <deployable>
                            <groupId>com.group</groupId>
                            <type>war</type>
                            <artifactId>my-webapp</artifactId>
                            <properties>
                                <context>/path</context>
                            </properties>
                        </deployable>                           
                    </deployables>
                </deployer>                 
            </configuration>                
        </plugin>
    </plugins>
</build>

I use the plugin by starting mvn cargo:start.

There is no error log output.

[INFO] [cargo:start]
[INFO] [beddedLocalContainer] Jetty 7.x Embedded starting...
2011-01-17 18:57:44.586:INFO::jetty-7.2.0.v20101020
2011-01-17 18:57:44.663:INFO::Extract jar:file:/tmp/cargo/conf/cargocpc.war!/ to /tmp/jetty-0.0.0.0-7070-cargocpc.war-_cargocpc-any-/webapp
2011-01-17 18:57:45.082:INFO::Started [email protected]:7070
[INFO] [beddedLocalContainer] Jetty 7.x Embedded started on port [7070]

How can I tell Cargo to load the specified war-File?

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

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

发布评论

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

评论(4

深巷少女 2024-10-19 04:13:02

好的,我现在开始工作了。

看起来,cargo 会默默地忽略任何快照依赖项。所以你必须先发布一个项目,然后才能在货物项目中使用它。

可能这是一个错误。我无法想象这种行为有任何合理的理由。

(我上面发布的 pom 文件也不正确,您必须适应 Robin 在他的答案中建议的更改)

Ok, I got it to work now.

As it seems, cargo silently ignores any snapshot dependencies. So you have to release a project before using it in a cargo-project.

Probably this is a bug. I can't imagine any sensible reason for this behaviour.

(also the pom-File I posted above was not correct, you have to adapt the changes that Robin suggests in his answer)

策马西风 2024-10-19 04:13:02

试试这个。将您的配置类型设置为独立并将部署放入配置中。确保存在正确的项目依赖关系以解决战争。

            <configuration>
                <type>standalone</type>
                <properties>
                    <cargo.servlet.port>7070</cargo.servlet.port>
                    <cargo.logging>high</cargo.logging>
                </properties>
                <deployables>
                    <deployable>
                        <groupId>com.group</groupId>
                        <type>war</type>
                        <artifactId>my-webapp</artifactId>
                        <properties>
                            <context>/path</context>
                        </properties>
                    </deployable>                           
                </deployables>                
             </configuration>           

Try this. Set your configuration type to standalone and put the deployables in the configuration. Make sure the correct project dependency exists to resolve the war.

            <configuration>
                <type>standalone</type>
                <properties>
                    <cargo.servlet.port>7070</cargo.servlet.port>
                    <cargo.logging>high</cargo.logging>
                </properties>
                <deployables>
                    <deployable>
                        <groupId>com.group</groupId>
                        <type>war</type>
                        <artifactId>my-webapp</artifactId>
                        <properties>
                            <context>/path</context>
                        </properties>
                    </deployable>                           
                </deployables>                
             </configuration>           
青瓷清茶倾城歌 2024-10-19 04:13:02

如果您首先进行部署,例如运行命令“mvn Cargo:deploy”,然后运行“mvn Cargo:start”,那么它似乎可以更好地工作

Its seems it could work better if you first do the deployment say run a command "mvn cargo:deploy" then run a "mvn cargo:start"

万劫不复 2024-10-19 04:13:02

如果您只想部署在嵌入式 Jetty 上,则可能不需要 Cargo。只需在您的网络应用程序的 pom.xml 中使用它即可:

  <build>
    ...
    ...
    <plugins>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>7.2.2.v20101205</version>
            <configuration>
              <scanIntervalSeconds>10</scanIntervalSeconds>
              <webAppConfig>
                <contextPath>/path</contextPath>
              </webAppConfig>
              <connectors>
                <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                  <port>7070</port>
                  <maxIdleTime>60000</maxIdleTime>
                </connector>
            </connectors>
            </configuration>
        </plugin>
        ...
        ...
    </plugins>
    ...
    ...
  </build>

构建并启动 Jetty 用户

 mvn clean install jetty:run

If you just want to deploy on embedded Jetty, you may not need Cargo. Just use this, in your web-app's pom.xml:

  <build>
    ...
    ...
    <plugins>
        <plugin>
            <groupId>org.mortbay.jetty</groupId>
            <artifactId>jetty-maven-plugin</artifactId>
            <version>7.2.2.v20101205</version>
            <configuration>
              <scanIntervalSeconds>10</scanIntervalSeconds>
              <webAppConfig>
                <contextPath>/path</contextPath>
              </webAppConfig>
              <connectors>
                <connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
                  <port>7070</port>
                  <maxIdleTime>60000</maxIdleTime>
                </connector>
            </connectors>
            </configuration>
        </plugin>
        ...
        ...
    </plugins>
    ...
    ...
  </build>

to build and start Jetty user

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