3

I am setting up a simple server project in eclipse (using a Glassfish as a server if it's relevant). I cannot seem to add a Servlet though. Unlike another question I've seen where a project cannot be selected I can select the project, but the finish or next buttons remain disabled. I tried manually creating a class that extends HttpServlet ahead of time and selecting but it the finish and next buttons are still disabled:

Custom 'WebService' servlet is selected but finish is disabled

I am running Eclipse 4.3, and I have tried starting it with -clean. Beyond that I'm not sure what to try.

EDIT:

As I said I orginally tried to create a new class using the dialog and only when that did not work did I create my WebService class. Here is what I orignally tried (using NewWebService as the name since WebService now already exists)

I cannot create new new class either

Fr33dan
  • 4,227
  • 3
  • 35
  • 62
  • Is the project in which you are trying to add the servlet a dynamic web project? – Nikos Paraskevopoulos Sep 30 '13 at 15:47
  • Did you try without using an existing servlet ? , The wizard is supposed to create the servlet and also web.xml servlet mapping for you. – Tito Sep 30 '13 at 15:49
  • @NikosParaskevopoulos Yes, it is a dynamic web project – Fr33dan Sep 30 '13 at 16:18
  • @TitoCheriachan Yes, I was originally trying to create from here but when it did not work. That was when I tried creating one myself. If there is no way to get the dialog functioning I will attempt to make it myself but I'm still very new to this so having eclipse do it for me would be extremely helpful. – Fr33dan Sep 30 '13 at 16:19
  • Is the WebService class that you have selected a servlet? Could you provide us the screen shot of the methods that are present? Or You can create a new one and then copy paste the code from WebService. – Vishnu Prasad Kallummel Oct 09 '13 at 09:41
  • @VishnuPrasadKallummel It is definitely a servlet, but as I stated I also tried to create a new one using the dialog but it did not work then either. This question was created before any code had been written. The `WebService` class I used here was an implementation of `HttpServlet` with the overloaded methods (`doGet`,`doPost`,and `doPut`) empty. I have since mapped it manually in the `web.xml` and added code that performs perfectly. – Fr33dan Oct 10 '13 at 13:31

2 Answers2

2

Although the question is already marked as answered. There could be other reason to have "next" or "finish" buttons grayed out in "Create Servlet" Dialog.

This could happen, if the PROJECTNAME/WebContent/WEB-INF/web.xml file is corrupt by i.e. misspelled tags or attributes.

code_angel
  • 1,537
  • 1
  • 11
  • 21
1

@Fr33dan: Check if dynamic web Module is checked in in your project facets.Also is this a maven project?


In the screen shot you provided it seems like you are checking the box Use an existing Servlet class or JSP. Just uncheck it and it should work fine, you will be able to create new class.

user2821894
  • 988
  • 2
  • 11
  • 20
  • Dynamic web module is selected, and I'm not sure what it means to be a Maven project so I am not sure. (I am new to Java EE coming from experience in Java SE). I created it as a "Dynamic Web Project" in Eclipse if that is a clue. – Fr33dan Oct 10 '13 at 13:41
  • @Fr33dan:I got what your problem is. I edited my answer above. If that works for you please accept the answer. – user2821894 Oct 10 '13 at 13:52
  • As I have stated multiple times. I was originally trying to create a new class using the dialog and only when that did not work did I create the class ahead of time. – Fr33dan Oct 10 '13 at 14:12
  • Ok. I presume that you have JDK installed on your machine. In Eclipse go to properties-javabuildpath-libraries-addLibrary-JRE SystemLibrary-select jdk.Also select if you have servlet-api.jar – user2821894 Oct 10 '13 at 14:54
  • 2
    So I already had the JDK (otherwise non of the other projects would work) but the mention of servlet-api.jar sent me on the right path. My Eclipse installation was not the "Eclipse for Java EE" package provided but the Vanilla installation to which I added the Java EE plugins (I've been running it for years now and did not want to lose my configurations). I should have also installed the "Java Web Development Tools" which contains servlet-api.jar. As noted here: http://stackoverflow.com/a/4076706/1111886 one should never add the jar files manually. After installing it works – Fr33dan Oct 10 '13 at 15:29