Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
509 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...