如何在没有 ant 或 maven 的情况下在 Eclipse 中创建一个战争文件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4032421/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 19:42:50  来源:igfitidea点击:

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

eclipseservletswar

提问by Jonas

I am using Eclipse IDE for Java DevelopersHelios. 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.

我正在为 Java 开发人员Helios使用Eclipse IDE。之前主要是做桌面应用,现在想学习Servlets。我已经在我的电脑上安装了 Jetty。我使用 Eclipse 用 Ja​​va 编写了一个简单的 Servlet。但是我如何编译它并将其导出到 Eclipse 中的 war 文件?我找到了一些用 Ant 做的教程,但如果可能的话,我想在 Eclipse 中使用它。

Here is my Servlet:

这是我的 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.

如何在 Eclipse 中编译它并将其导出为 war 文件?没有 Ant 或 Maven。所以我可以在 Jetty 中部署它。

回答by JoseK

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.

编辑:正如@nos 所推断的那样,OP 使用的是“Java 开发人员的 Eclipse IDE”而不是“Java EE 开发人员的 Eclipse IDE”。以下仅与后者有关。

Assuming you created this as a Dynamic Web projectin Eclipse, just

假设您在 Eclipse中将其创建为动态 Web 项目,只需

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 projectinto one first

如果您没有将其创建为动态 Web 项目,则可以先将您的静态 Web 项目转换为一个