我希望我的集成测试能够在http://localhost:8080/messaging点击货物的tomcat,但货物(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目录中看到消息或消息-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,我可以改变测试,但是什么是快速提取工件版本?
理想情况下,我希望货物能正确部署,但目前还不清楚如何。
答案 0 :(得分:2)
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.
你能解决这个问题吗?
另外,我认为上下文名称不应该有前导/
。
答案 1 :(得分:1)
如何设置finalName属性?
如果你在POM中设置<finalName>messaging</finalName>
,这应该可以解决问题。
答案 2 :(得分:1)
Deployables
代码不应该放在Deployer
标记内:
<deployables>
<deployable>
<properties>
<context>/messaging</context>
</properties>
</deployable>
</deployables>