Eclipse - java.lang.ClassNotFoundException [英] Eclipse - java.lang.ClassNotFoundException

查看:108
本文介绍了Eclipse - java.lang.ClassNotFoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试从Eclipse启动我的JUnit测试时,我得到一个ClassNotFoundException。当从控制台运行mvn test时 - 一切正常。此外,Eclipse中没有报告问题。

When trying to start my JUnit-Test out of Eclipse, I get a "ClassNotFoundException". When running "mvn test" from console - everything works fine. Also, there are no problems reported in Eclipse.

我的项目结构如下:


  • 父项目(pom-packaging)


    • Web项目(war-packaging - 我的JUnit测试在这里)

    • Flex项目

    • 配置项目

    编辑:如何找不到班级?这是一个简单的HelloWorld-Application,没有特殊的库。

    edit: How can the class not be found? It's a simple HelloWorld-Application with no special libraries.

    这是我的JUnit的运行配置:
    alt text http://www.walkner.biz/_temp/runco​​nfig.png

    Here's my JUnit's run-configuration: alt text http://www.walkner.biz/_temp/runconfig.png

    Testclass(但正如我所说;它不适用于简单的HelloWorld ...):

    Testclass (but as I said; it doesn't work with a simple HelloWorld either...):

    import org.junit.After;
    import org.junit.Assert;
    import org.junit.Before;
    import org.junit.Test;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import biz.prognoserechnung.domain.User;
    import biz.prognoserechnung.domain.UserRepository;
    import biz.prognoserechnung.domain.hibernate.UserHibernateDao;
    
    public class UserDaoTest {
    /**
     * the applicationcontext.
     */
    private ApplicationContext ctx = null;
    
    /**
     * the user itself.
     */
    private User record = null;
    
    /**
     * Interface for the user.
     */
    private UserRepository dao = null;
    
    @Before
    public void setUp() throws Exception {
    String[] paths = { "WEB-INF/applicationContext.xml" };
    ctx = new ClassPathXmlApplicationContext(paths);
    dao = (UserHibernateDao) ctx.getBean("userRepository");
    }
    
    @After
    public void tearDown() throws Exception {
    dao = null;
    }
    
    @Test
    public final void testIsUser() throws Exception {
    Assert.assertTrue(dao.isUser("John", "Doe"));
    }
    
    @Test
        public final void testIsNoUser() throws Exception {
        Assert.assertFalse(dao.isUser("not", "existing"));
            Assert.assertFalse(dao.isUser(null, null));
            Assert.assertFalse(dao.isUser("", ""));
        }
    }
    


    推荐答案

    方法有帮助!
    Eclipse - java.lang.ClassNotFoundException

    尝试检查junit运行配置的类路径:

    Try to check the classpath of the junit run configuration:


    1. 打开运行配置

    2. 单击要开始的jUnit测试

    3. 转到类路径选项卡

    4. 尝试添加一个文件夹(单击用户条目,单击高级,单击添加文件夹,单击确定并搜索您的测试类的输出文件夹(那些您在projektproperties下的java构建路径,源))

    1. Open your run configurations
    2. Click on the jUnit-Test you want to start
    3. go to the classpath tab
    4. Try to add a folder (click on user entries, click on advanced, click on add folders, click on ok and search the outputfolder for your test classes(those you find under projektproperties java build path, source))

    适用于我。

    这篇关于Eclipse - java.lang.ClassNotFoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆