Arquillian testing with Maven in Eclipse: Deployment scenario issue (Glassfish embedded example)

To run a test with Arquillian using Maven you might consider embedded, local or remote containers. You can set them all in your pom.xml file and specify deployment profiles like the following:

 <profile>
			<id>arquillian-glassfish-embedded</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<dependencies>
				<dependency>
					<groupId>org.jboss.arquillian.container</groupId>
					<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
					<version>1.0.0.CR4</version>
					<scope>test</scope>
				</dependency>
				<dependency>
					<groupId>org.glassfish.main.extras</groupId>
					<artifactId>glassfish-embedded-all</artifactId>
					<version>4.0</version>
					<scope>provided</scope>
				</dependency>

				<dependency>
					<groupId>org.glassfish.jersey.core</groupId>
					<artifactId>jersey-client</artifactId>
					<version>2.4.1</version>
					<scope>provided</scope>
				</dependency>

				<dependency>
					<groupId>org.glassfish.jersey.containers</groupId>
					<artifactId>jersey-container-servlet</artifactId>
					<version>2.4.1</version>
					<scope>provided</scope>
				</dependency>

			</dependencies>
		</profile>

The container must be configured in the arquillian.xml file. A simple one might look like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://jboss.org/schema/arquillian"
   xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
   <!--  this is only needed if you want to override AS7  -->
   <!--  <defaultProtocol type="Servlet 3.0"/> -->
   <container qualifier="arquillian-glassfish-embedded">
   	<configuration>
   		<property name="bindHttpPort">9090</property>
   	</configuration>
   </container>
   <!-- 
   <container qualifier="tomcat">
   	<configuration>
   		<property name="user">tomcat</property>
   		<property name="pass">tomcat</property>
   	</configuration>
   </container>
    -->
</arquillian>

Setting the container in the pom.xml and the arquillian.xml files is not enough to run the test in Eclipse.
You would get the following error:

org.jboss.arquillian.container.test.impl.client.deployment.ValidationException: DeploymentScenario contains a target (_DEFAULT_) not matching any defined Container in the registry.
Please include at least 1 Deployable Container on your Classpath.
          at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.throwNoContainerFound(DeploymentGenerator.java:250)
          at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.throwTargetNotFoundValidationException(DeploymentGenerator.java:243)
          at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.validate(DeploymentGenerator.java:102)
          at org.jboss.arquillian.container.test.impl.client.deployment.DeploymentGenerator.generateDeployment(DeploymentGenerator.java:84)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          at java.lang.reflect.Method.invoke(Method.java:597)
          at org.jboss.arquillian.core.impl.ObserverImpl.invoke(ObserverImpl.java:94)
          at org.jboss.arquillian.core.impl.EventContextImpl.invokeObservers(EventContextImpl.java:99)
          at org.jboss.arquillian.core.impl.EventContextImpl.proceed(EventContextImpl.java:81)
          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:135)
          at org.jboss.arquillian.core.impl.ManagerImpl.fire(ManagerImpl.java:115)
          at org.jboss.arquillian.core.impl.EventImpl.fire(EventImpl.java:67)
…

To make the test run you need to set the active maven profiles in Eclipse. Simply right click on the project and select Properties>Maven and add “arquillian-glassfish-embedded” in the Active maven profiles textbox.