更改 Maven 货物插件部署路径

发布于 2024-10-12 19:56:28 字数 3181 浏览 2 评论 0原文

我想让我的集成测试命中货物的 tomcat http://localhost:8080/messaging 但货物 (cargo- maven2-plugin:1.0.5) 更喜欢将我的消息传递项目部署为 /messaging-0.0.7-SNAPSHOT,如 tomcat 管理控制台和 target\tomcat6x\webapps 目录中所示。

因此,我尝试将这些行添加到货物配置中,认为它将获取默认工件:

 <deployer>
  <deployables>
   <deployable>
     <properties>
     <context>/messaging</context>
    </properties>
   </deployable>
  </deployables>
 </deployer>

但事实并非如此。它甚至没有尝试这样做,因为我在 target\tomcat6x\webapps 目录中没有看到 messages 或 messages-0.0.7-SNAPSHOT 。

当我像这样设置它时,也会发生同样的事情:

<configuration>
  <type>standalone</type>
 <wait>false</wait>
 <properties>
  <cargo.servlet.port>8080</cargo.servlet.port>
  <cargo.logging>high</cargo.logging>
 </properties>
 <deployer>
  <deployables>
   <deployable>
     <groupId>com.company.platform</groupId>
     <artifactId>messaging</artifactId>
     <type>war</type>
     <properties>
     <context>/messaging</context>
    </properties>
   </deployable>
  </deployables>
 </deployer>
</configuration>

这是完整的插件配置:

  <plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
 <execution>
  <id>start</id>
  <phase>pre-integration-test</phase>
  <goals>
   <goal>start</goal>
  </goals>
 </execution>
 <execution>
  <id>stop</id>
  <phase>post-integration-test</phase>
  <goals>
   <goal>stop</goal>
  </goals>
 </execution>
</executions>
<configuration>
  <type>standalone</type>
 <wait>false</wait>
 <properties>
  <cargo.servlet.port>8080</cargo.servlet.port>
  <cargo.logging>high</cargo.logging>
 </properties>
 <deployer>
  <deployables>
   <deployable>
     <properties>
     <context>/messaging</context>
    </properties>
   </deployable>
  </deployables>
 </deployer>
</configuration>

我的集成测试如下所示:

import junit.framework.TestCase;

import java.io.InputStream;
import java.net.URL;
import java.net.HttpURLConnection;
import java.sql.Time;

public class WebappTest extends TestCase
{
    public void testCallIndexPage() throws Exception
    {
        URL url = new URL("http://localhost:8080/messaging/");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.connect();
        assertEquals(200, connection.getResponseCode());
        InputStream is = connection.getInputStream();
        System.out.println(connection.getContent().getClass());

    }
}

进行的最佳方法是什么?知道它将成功部署为 hxxp://localhost:8080/messaging-0.0.7-SNAPSHOT,我可以更改测试,但是提取工件版本的快速方法是什么?

理想情况下,我希望货物能正确部署它,但目前还不清楚如何部署。

I want to have my integration test hit cargo's tomcat at http://localhost:8080/messaging but cargo (cargo-maven2-plugin:1.0.5) prefers to deploy my messaging project as /messaging-0.0.7-SNAPSHOT, as seen in the tomcat admin console and in the target\tomcat6x\webapps directory.

So I tried adding these lines to the cargo config, figuring that it will pick up the default artifact:

 <deployer>
  <deployables>
   <deployable>
     <properties>
     <context>/messaging</context>
    </properties>
   </deployable>
  </deployables>
 </deployer>

but it doesn't. It doesn't even attempt to since I don't see the messaging or messaging-0.0.7-SNAPSHOT in the target\tomcat6x\webapps directory.

The same thing happens when I set it up like so:

<configuration>
  <type>standalone</type>
 <wait>false</wait>
 <properties>
  <cargo.servlet.port>8080</cargo.servlet.port>
  <cargo.logging>high</cargo.logging>
 </properties>
 <deployer>
  <deployables>
   <deployable>
     <groupId>com.company.platform</groupId>
     <artifactId>messaging</artifactId>
     <type>war</type>
     <properties>
     <context>/messaging</context>
    </properties>
   </deployable>
  </deployables>
 </deployer>
</configuration>

Here's the full plugin config:

  <plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
 <execution>
  <id>start</id>
  <phase>pre-integration-test</phase>
  <goals>
   <goal>start</goal>
  </goals>
 </execution>
 <execution>
  <id>stop</id>
  <phase>post-integration-test</phase>
  <goals>
   <goal>stop</goal>
  </goals>
 </execution>
</executions>
<configuration>
  <type>standalone</type>
 <wait>false</wait>
 <properties>
  <cargo.servlet.port>8080</cargo.servlet.port>
  <cargo.logging>high</cargo.logging>
 </properties>
 <deployer>
  <deployables>
   <deployable>
     <properties>
     <context>/messaging</context>
    </properties>
   </deployable>
  </deployables>
 </deployer>
</configuration>

My integration test looks like this:

import junit.framework.TestCase;

import java.io.InputStream;
import java.net.URL;
import java.net.HttpURLConnection;
import java.sql.Time;

public class WebappTest extends TestCase
{
    public void testCallIndexPage() throws Exception
    {
        URL url = new URL("http://localhost:8080/messaging/");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.connect();
        assertEquals(200, connection.getResponseCode());
        InputStream is = connection.getInputStream();
        System.out.println(connection.getContent().getClass());

    }
}

What's the best way to proceed? Knowing that it will successfully deploy as hxxp://localhost:8080/messaging-0.0.7-SNAPSHOT, I could alter the test, but what would be a quick way to pull the artifact version in?

Ideally, I'd like to have cargo deploy it correctly, but it is unclear how.

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

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

发布评论

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

评论(3

下雨或天晴 2024-10-19 19:56:28

来自 Cargo 插件参考

About WAR contexts

    Many containers have their specific files for redefining context roots (Tomcat 
has context.xml, JBoss has jboss-web.xml, etc.). If your WAR has such a file, the 
server will most probably use the context root defined in that file instead of the 
one you specify using the CARGO deployer.

您是否遇到了这个问题?

另外,我认为上下文名称不应该以 / 开头。

From Cargo Plugin Reference,

About WAR contexts

    Many containers have their specific files for redefining context roots (Tomcat 
has context.xml, JBoss has jboss-web.xml, etc.). If your WAR has such a file, the 
server will most probably use the context root defined in that file instead of the 
one you specify using the CARGO deployer.

Could you be hitting this issue?

Also, I think context name should not have a leading /.

南…巷孤猫 2024-10-19 19:56:28

Deployables 标签不应位于 Deployer 标签内:

  <deployables>
   <deployable>
     <properties>
     <context>/messaging</context>
    </properties>
   </deployable>
  </deployables>

Deployables tag should not go inside Deployer tag:

  <deployables>
   <deployable>
     <properties>
     <context>/messaging</context>
    </properties>
   </deployable>
  </deployables>
征﹌骨岁月お 2024-10-19 19:56:28

设置 FinalName 属性怎么样?

如果您在 POM 中设置 messaging ,这应该可以解决问题。

What about setting the finalName property?

If you set <finalName>messaging</finalName> in your POM this should do the trick.

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