Link to home
Start Free TrialLog in
Avatar of william007
william007

asked on

Could not find the main class. Program will exit.

I am using eclipse. Followed is the code that I use, I get the error
---------------------------
Java Virtual Machine Launcher
---------------------------
Could not find the main class. Program will exit.
---------------------------
OK  
---------------------------
when I run it, what is the problem?

package myFolder;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class myClass extends HttpServlet {

      protected void doGet(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
            response.setContentType("text/html");
            PrintWriter out=response.getWriter();
            out.println("reponse as HTML");
      }
      protected void doPost(HttpServletRequest request, HttpServletResponse response)
                  throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request,response);
      }
public static void main(String args[]){}




}
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think ,
  servlet should not use main class. This is used in web application project.
U need to write jsp and servlet .
  If u want to create java class , then u can write main method .And call other method to do ur task.

U can directly call servlet ..but through url...

This is a servlet so it does not have a main class. This means that you cannot run it as objects suggests but instead you need to run it inside a servlet container such as Tomcat.

You need to download and setup Tomcat from here http://tomcat.apache.org/  but don't worry it's very simple :-)
Avatar of william007
william007

ASKER

Thanks,
This is due to the  run button is by default Run on a java file that I just deleted.
As before I thought that it is running the java files that are currently selected.
(Actually it is run on a file that we run before)
And now it is running after I explicitly choose the file I want to run by clicking the Arrow just beside the run button. Thansk for the help again:-)
no probs :)