Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 12473
  • Last Modified:

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[]){}




}
0
william007
Asked:
william007
1 Solution
 
objectsCommented:
you sure you're runn ing that class
do u right click it as select run>Run as application
0
 
ManishLeadCommented:
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...

0
 
bloodredsunCommented:
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 :-)
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
william007Author Commented:
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)
0
 
william007Author Commented:
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:-)
0
 
objectsCommented:
no probs :)
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now