我在eclipse中引进了一个新工程.但当我写了一个测试类运行的时候为什么显示找不到"main"方法.
错误提示为:"The selection does not contain a main type"

解决方案 »

  1.   

    RUN 的下拉选项里选 RUN AS JUNIT
      

  2.   

    public class Main {
    /**
     * Logger for this class
     */
    private static final Logger logger = Logger.getLogger(Main.class); private static ApplicationContext applicationContext; /**
     * @param args
     */
    public static void main(String[] args) {
    // 输出系统日志
    logger.error("netkeeper 系统开始初始化 >>>>>>");
    // 初始化配置管理器
    ConfigUtil.init("netkeeper.xml");
    DESUtil.init();
    // 初始化spring
    applicationContext = new ClassPathXmlApplicationContext(new String[] {
    "register_server_datasource.xml", 
    "business-definition.xml","timer-task.xml" });
    // 启动客户端注册监听器
    ServerListener.listen();
    ClientServerBean clientManager = new ClientServerBean();
    ContainerMonitor cacheMinitor = new ContainerMonitor();
    try {
    clientManager.registeMySelf();
    cacheMinitor.registeMySelf();
    } catch (JMException e) {
    e.printStackTrace();
    }
    // 输出系统日志
    logger.error("netkeeper 系统开始初始化完毕 <<<<<<");
    } public static ApplicationContext getApplicationContext() {
    return applicationContext;
    }}
      

  3.   

    首先这个类要继承  junit.framework.TestCase 其次把JUNIT类库加载到你的CLASSPATH
    然后运行 RUN AS JUNIT
      

  4.   

    程序应该没社么问题,看看CLASSPATH是否设好了,有没有加载到第三方的JAR和XML文件
      

  5.   

    我晕啊~~为什么把类加进来了还是找不到main
      

  6.   

    http://www.56dao.com:80//regnew.bbscs?rec=76695
      

  7.   

    测试代码写上来据我观察楼主没用junit
      

  8.   

    遇到过这个问题,你可以试试这个方法:
        eclipse 工具框最右边,选择java模试。再试试