Tomee maven安装目标发送:无法初始化类org.apache.openejb.util.JuliLogStreamFactory

时间:2015-01-13 08:22:10

标签: java eclipse maven junit tomee

我有以下具有一个集成测试的类:

@LocalClient
public class AdminDummyTest extends TestCase {


private static final String propFileName = "\\config\\testconfig.properties";
private Config              config;
private Properties          p;
private Context             context;
@EJB
IBasicConfigDao             basicDaoConfig;

@Override
protected void setUp() throws IOException, NamingException {
    config = new Config();

    p = config.getPropertiesFromFile(propFileName);
    p.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.openejb.client.LocalInitialContextFactory");
    context = new InitialContext(p);

    context.bind("inject", this);

}

public void testGetDataFromDatabase() throws NamingException {
    BasicConfig bs = basicDaoConfig.getFirst();
    assertEquals("BIZ", bs.getType());
    assertEquals("Description", bs.getValue());
}

}

当我通过右键单击测试类并在eclipse中选择run as junit test来运行此测试时,测试工作正常,但是当我运行maven安装目标(也运行测试)时,我得到以下stacktrace:

testGetDataFromDatabase(com.mycomp.base.admin.AdminDummyTest)  Time elapsed: 0.094 sec  <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class   org.apache.openejb.util.JuliLogStreamFactory
at org.apache.openejb.util.Logger.configure(Logger.java:96)
at org.apache.openejb.util.Logger.<clinit>(Logger.java:39)
at org.apache.openejb.util.OptionsLog.<init>(OptionsLog.java:31)
at org.apache.openejb.util.OptionsLog.install(OptionsLog.java:39)
at org.apache.openejb.core.LocalInitialContextFactory.init(LocalInitialContextFactory.java:96)
at org.apache.openejb.core.LocalInitialContextFactory.init(LocalInitialContextFactory.java:62)
at org.apache.openejb.core.LocalInitialContextFactory.getInitialContext(LocalInitialContextFactory.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307)
at javax.naming.InitialContext.init(InitialContext.java:242)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
at com.mycomp.base.admin.AdminDummyTest.setUp(AdminDummyTest.java:41)
at junit.framework.TestCase.runBare(TestCase.java:139)
at junit.framework.TestResult$1.protect(TestResult.java:122)
at junit.framework.TestResult.runProtected(TestResult.java:142)
at junit.framework.TestResult.run(TestResult.java:125)
at junit.framework.TestCase.run(TestCase.java:129)
at junit.framework.TestSuite.runTest(TestSuite.java:255)
at junit.framework.TestSuite.run(TestSuite.java:250)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:84)
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

我在网上搜索了这个错误,但无法解决问题。我正在使用Tomee 1.7.0 plus作为EJB容器。我将在下面注意项目的主题:

<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycomp.base.admin</groupId>
<artifactId>Base_Admin</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>

<parent>
    <groupId>com.mycomp.base</groupId>
    <artifactId>Base_Parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <relativePath>../Base_Parent/pom.xml</relativePath>
</parent>
<dependencies>
    <dependency>
        <groupId>com.mycomp.base.commons</groupId>
        <artifactId>Base_Commons</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>

    <dependency>
        <groupId>com.mycomp.base.config</groupId>
        <artifactId>Base_Config</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>tomee-embedded</artifactId>
        <version>1.6.0</version>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0-6-tomcat</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>openejb-loader</artifactId>
        <version>4.7.0</version>

    </dependency>
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>openejb-core</artifactId>
        <version>4.7.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>openejb-client</artifactId>
        <version>4.7.0</version>

    </dependency>
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>openejb-jee</artifactId>
        <version>4.7.0</version>

    </dependency>
    <dependency>
        <groupId>org.apache.openejb</groupId>
        <artifactId>openejb-api</artifactId>
        <version>4.7.0</version>

    </dependency>
    <dependency>
        <groupId>org.apache.openjpa</groupId>
        <artifactId>openjpa</artifactId>
        <version>2.4.0</version>
    </dependency>

</dependencies>

我知道JuliLogStreamFactory位于openejb-core包中,我已经添加了包含'test'范围的包(请参阅pom.xml文件),但由于某种原因,这不起作用。如果需要其他信息,请告诉我。


我不确定它是否会有所帮助,但我改变了测试(在线搜索其他方法进行测试)但遇到了同样的问题(测试运行正常,'run as junit test'但在调用maven install时失败):

@PropertyFile("\\config\\testconfig.properties")
@RunWith(EJBContainerRunner.class)
public class AdminDummyTest extends TestCase {

    @TestResource
    private Context             context;
    @EJB
    IBasicConfigDao             basicDaoConfig;

    @Override
    protected void setUp() throws NamingException, IOException {
        basicDaoConfig = (IBasicConfigDao)     context.lookup("java:global/Base_Admin/BasicConfigDao");

}

    @Test
    public void testGetDataFromDatabase() throws NamingException {
        BasicConfig bs = basicDaoConfig.getFirst();
        assertEquals("BIZ", bs.getType());
        assertEquals("Description", bs.getValue());
    }
}

1 个答案:

答案 0 :(得分:1)

我猜你的类路径搞砸了(tomee 1.6应该使用openejb 4.6或者使用openejb 1.7 tomee 1.7)。确保tomee / openejb按照前面的说明进行对齐,你应该摆脱这个问题。