Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arquillian: Create a WebArchive from an existing war using ShrinkWrap

I am trying to deploy an existing war from another maven project in Arquillian. I have resolved the war and have it copied to the target directory of my Arquillian project.

I try to create it below:

@Deployment
public static WebArchive createDeployment() {

    return (WebArchive) ShrinkWrap.create(ZipImporter.class, "MyWarToTest.war").importFrom(
            new File("target/MyWarToTest.war"));

}

However, I am getting a class cast exception.

Caused by: java.lang.ClassCastException: org.jboss.shrinkwrap.impl.base.importer.zip.ZipImporterImpl cannot be cast to org.jboss.shrinkwrap.api.Archive

I am guessing that I should be trying to create the war a different way?

like image 269
cbeaudin Avatar asked Jul 23 '13 13:07

cbeaudin


2 Answers

Adding my 2 cents. Even more quick (and with the same result) is the following method:

@Deployment
public static WebArchive createDeployment() {
    return ShrinkWrap.createFromZipFile(WebArchive.class, new File("target/payloadPlan.war"));
}
like image 166
Henk de Vries Avatar answered Sep 21 '22 05:09

Henk de Vries


I found the answer. I needed to add the .as(WebArchive.class) to the end of the call.
It needs to look like this:

@Deployment
public static WebArchive createDeployment() {

    return ShrinkWrap.create(ZipImporter.class, "payloadPlan.war").importFrom(new File("target/payloadPlan.war"))
            .as(WebArchive.class);

}

I found the answer here: http://zezutom.blogspot.com/2012/08/going-mobile-with-arquillian.html

like image 20
cbeaudin Avatar answered Sep 19 '22 05:09

cbeaudin