如何在没有ant或maven的Eclipse中创建一个war文件? [英] How to create an war file in Eclipse without ant or maven?

查看:170
本文介绍了如何在没有ant或maven的Eclipse中创建一个war文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Eclipse IDE for Java Developers Helios。以前我主要做过桌面应用程序,但现在我想了解一下Servlet。我已经在我的电脑上安装了Jetty。并且我使用Eclipse在Java中编写了一个简单的Servlet。但是如何编译它并将其导出到Eclipse中的war文件?我已经发现一些教程使用Ant进行,但是如果可能,我希望在Eclipse中进行本地化。

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.

这是我的Servlet:

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>");
    }
}

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

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 IDE for Java Developers,而不是Eclipse IDE for Java EE Developers。以下仅适用于后者。

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.

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

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

右键单击

project name, > Export > WAR file

,并填写要求的详细信息。

and fill in the details it asks for.

如果您没有将其创建为Dynamic Web Project,则您可以将您的静态网页项目转换为第一个

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

这篇关于如何在没有ant或maven的Eclipse中创建一个war文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆