How to create an war file in Eclipse without ant or maven?

34,792

Edit: As @nos has inferred, the OP was using "Eclipse IDE for Java Developers" and not "Eclipse IDE for Java EE Developers". The below is only relevant for the latter.

Assuming you created this as a Dynamic Web project in Eclipse, just

right-click on the

project name, > Export > WAR file

and fill in the details it asks for.

If you didnt create this as Dynamic Web Project, you can convert your static web project into one first

Share:
34,792
Jonas
Author by

Jonas

Passionated Software Developer interested in Distributed Systems

Updated on October 28, 2020

Comments

  • Jonas
    Jonas over 3 years

    I am using Eclipse IDE for Java Developers Helios. I have mainly done desktop applications before but now I would like to learn about Servlets. I have installed Jetty on my computer. And I wrote a simple Servlet in Java using Eclipse. But how do I compile it and export it to a war file in Eclipse? I have found some tutorials doing it with Ant, but I would like to do it native in Eclipse if possible.

    Here is my Servlet:

    package org.jonas;
    
    // some imports from java.io, java.servlet and java.servlet.http
    
    public class MyServlet extends HttpServlet {
        public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws IOException, ServletException {
    
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
    
            String name = request.getParameter("name");
    
            out.println(
                    "<html><body>" +
                    "<h1>" + name + "</h1>" +
                    "</body></html>");
        }
    }
    

    How can I compile it and export it as a war file in Eclipse? Without Ant or Maven. So I can deploy it in Jetty.

  • Jonas
    Jonas over 13 years
    I don't have a Dynamic Web project alternative. In the New Project dialog, I just have Java Project and Java Project from Existing Ant Buildfile under the Java directory.
  • nos
    nos over 13 years
    @Jonas Sounds like you have "Eclipse IDE for Java Developers" and not "Eclipse IDE for Java EE Developers" , the latter has more support for creating Servlets/JSPs.
  • Jonas
    Jonas over 13 years
    @nos: True, is it possible to upgrade via plugins? I use my Eclipse for many other things that already is installed.
  • JoseK
    JoseK over 13 years
    @Jonas: Regarding upgrade via plugins. Not that I know of - you'd have to download the "Java EE" version and then import your old projects into new installation.
  • Jonas
    Jonas over 13 years
    I thought that Eclipse was a flexible IDE where I could just add new plugins if I needed. But that was wrong, I have to download a hole new Eclipse for some things :( I have downloaded the Java EE edition now. But it doesn't seem possible to convert my Java Project to a Dynamic Web Project so I have to create a new Dynamic Web Project. I choosed New Servlet and surprisingly the generated code has errors on @WebServlet("/MyServlet") but I will work on this. Thanks for the help.
  • JoseK
    JoseK over 13 years
    @Jonas: But see, the support is better for Java EE, else this would fail in your server and would be more painful to debug ;)
  • Dan Bourque
    Dan Bourque about 12 years
    You can add the necessary software, instead of downloading Eclipse's Java EE edition from scratch. I know it's too late for you Jonas, but future readers might benefit. Just install the "Eclipse Java EE Developer Tools" package from Eclipse's update site.