java.lang.NoSuchMethodError: main Exception in thread "main"If you have done any Java programming at all, then you probably recognize what this error means. Java is looking for a method named main and can't find it. The solution is to mark the servlet as a servlet.
The next problem is that servlets must be run in a web app. If you try to run a servlet that is not in a web app, this is the error that you get from NetBeans:
Exception occurred in Request ProcessorIf you inspect the details for the error, you will see this:
Annotation: Exception occurred in Request Processor java.lang.NullPointerException at org.netbeans.modules.web.core.jsploader.ServletDataObject.getModule(ServletDataObject.java:682) at org.netbeans.modules.j2ee.deployment.execution.ServerDebuggerType$1.run(ServerDebuggerType.java:84) at org.openide.util.Task.run(Task.java:136) at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:330) [catch] at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:686)
Note: If you are working in the AUL, then you could try to mount the servlets directory, but you will be prevented from using it because of the security permissions imposed by the web.xml file.
<?xml version="1.0" encoding="ISO-8859-1"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> </web-app>
You should also create subdirectories of classes for my downey package, and your user-name package.
You can now mount the local directory in NetBeans. Place your .java files in the classes directory (in the correct package).
If all goes well, then NetBeans will mount the web app directory and
the classes directory separately (and automatically). The file structure
should look like this when you are done.
Note that NetBeans has created some additional directories for the web app:
META-INF and lib. Also note that in the WEB-INF directory
the icon associated with the
classes directory is different from the icon for the lib directory.
This is because classes is also mounted as a file system.