更改 Maven 货物插件部署路径
我想让我的集成测试命中货物的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
来自 Cargo 插件参考,
您是否遇到了这个问题?
另外,我认为上下文名称不应该以
/
开头。From Cargo Plugin Reference,
Could you be hitting this issue?
Also, I think context name should not have a leading
/
.Deployables
标签不应位于Deployer
标签内:Deployables
tag should not go insideDeployer
tag:设置 FinalName 属性怎么样?
如果您在 POM 中设置
messaging
,这应该可以解决问题。What about setting the finalName property?
If you set
<finalName>messaging</finalName>
in your POM this should do the trick.