I have searched through Stackoverflow to find an answer for my problem, found some very similar problems, but no answer.
What I am trying to do: Create a simple junit test, where a Glassfish 4.1 embedded container is started, and a simple operation of an EJB is tested.
Sample EJB:
@Stateless
@LocalBean
public class ExampleBean {
public int meaningOfLife() {
return 42;
}
}
Pretty simple. Here is my unit test:
public class BasicTest {
@EJB
private ExampleBean examplebean;
private static Context context;
private static EJBContainer container;
@BeforeClass
public static void init() {
Map<String,Object> props = new HashMap<String,Object>();
//props.put(EJBContainer.MODULES, new File("target/classes"));
props.put(EJBContainer.MODULES, new File("D:\\Development\\IDE\\workspace-templates\\jee7-template\\template-service\\target"));
try {
container = EJBContainer.createEJBContainer(props);//.getContext().bind("inject", this);
context = container.getContext();
} catch (Exception e) {
e.printStackTrace();
}
}
}
My pom.xml dependencies:
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-static-shell</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>D:\\Development\\Servers\\glassfish4.1-activiti\\glassfish\\lib\\embedded\\glassfish-embedded-static-shell.jar</systemPath>
</dependency>
I have also tried with adding the following dependencies:
<dependency>
<groupId>org.glassfish.main.ejb</groupId>
<artifactId>ejb-container</artifactId>
<version>4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.ejb</groupId>
<artifactId>javax.ejb-api</artifactId>
<version>3.2</version>
<scope>test</scope>
</dependency>
And the results: The embedded GF 4.1 container couldn't load that simple EJB (it is there in the target/classes folder, after a maven compile).
I get the following errors, based on the different code changes (like using properties to pass to the container or not):
GF 4.1 Embedded UnsatisfiedDependencyException
GF 4.1 Embedded Can't deploy EJB classes
The code I have pasted is giving the last error message linked.
And I don't understand. Everywhere I look for information, says this should work.
Also, if I try this, with OpenEJB container (sadly it is just jee6), it works fine.
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.7.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0-6</version>
<scope>test</scope>
</dependency>
Thanks for the help!