错误:在类mypackage.Mainclass中找不到主方法,请将main方法定义为:public static void main(String [] args)

时间:2016-06-13 08:38:57

标签: java eclipse

我正在尝试在eclipse中运行一个java应用程序但它的显示

  

错误:在mypackage.Mainclass类中找不到主方法,请将main方法定义为:public static void main(String [] args)

即使它包含正确:

package mypackage;

import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;
import javax.transaction.Transaction;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class Mainclass {
public static void main(String[] args) {  

       //creating configuration object  
        Configuration cfg=new Configuration();  
        cfg.configure("hibernate.cfg.xml");//populates the data of the         configuration file  

        //creating seession factory object  
        SessionFactory factory=cfg
            .buildSessionFactory();  

        //creating session object  
        Session session=factory.openSession();  

    //creating transaction object  
        Transaction t=(Transaction) session.beginTransaction();  

        Employee e1=new Employee();  
        e1.setId(115);  
        e1.setFirstName("sonoo");  
        `enter code here`e1.setLastName("jaiswal");  

    session.persist(e1);//persisting the object  

    try {
        t.commit();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (RollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HeuristicMixedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (HeuristicRollbackException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }//transaction is committed  
    session.close();  

    System.out.println("successfully saved");  
}
}

当我点击Run As-> Java Application时,它通过显示我的项目名称未显示的对话框要求我选择Java Application。

0 个答案:

没有答案