在这些说明之后尝试设置 JPA+EJB 测试:http: //ctpjava.blogspot.fi/2009/10/unit-testing-ejbs-and-jpa-with.html
似乎很少有我无法完全正确的问题。首先我得到这个错误(我可以解决这个问题,但它仍然需要修复):
SEVERE: EJB6004:Specified application server installation location [C:\Users\<userName>\.m2\repository\org\glassfish\extras\glassfish-embedded-all\domains\domain1] does not exist.
找到了这个站点,它提供了(更正确的?)要设置的属性:http: //docs.oracle.com/cd/E18930_01/html/821-2424/gjlde.html
并将我的测试设置修改为:
import javax.ejb.embeddable.EJBContainer;
import javax.naming.Context;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
...
@BeforeClass
public static void createContainer() {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(EJBContainer.MODULES, new File("target/classes"));
properties.put("installation.root", "./src/test/glassfish");
properties.put("configuration.file", "./src/test/glassfish/domains/domain1/config/domain.xml");
container = EJBContainer.createEJBContainer(properties);
ctx = container.getContext();
}
在 pom.xml 中,我似乎需要以下内容:
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.9.1.0</version>
<scope>test</scope>
</dependency>
<!-- Must be before java-ee -->
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
错误指向用户目录,我可以通过在那里设置所需的东西(并通过它)来通过它,但这不是一个合适的地方,因为所有东西都必须通过 SVN 可用。
根据后一个链接,我认为我设置了正确的属性,但这些似乎被忽略了。也许我错过了一些明显的东西?