简体   繁体   English

使用 Eclipse EE 将动态 Web 项目重新部署到 Wildfly 服务器

[英]Redeploy Dynamic Web Project to Wildfly Server with Eclipse EE

I am creating a dynamic web project using Eclipse EE to run on a Wildfly v18 server.我正在使用 Eclipse EE 创建一个动态 Web 项目以在 Wildfly v18 服务器上运行。 I setup a test servlet just to ensure that my setup is working and mapped it in the web.xml file:我设置了一个测试 servlet 只是为了确保我的设置正常工作并将其映射到 web.xml 文件中:

@WebServlet("/Test")
public class Test extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("<h1>Test</h1>");
    }

}

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
    <servlet>
        <servlet-name>test</servlet-name>
        <servlet-class>com.nhbb.test.Test</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>test</servlet-name>
        <url-pattern>/test</url-pattern>
    </servlet-mapping>
</web-app>

The servlet works and I get the desired results when I open localhost:8080/TestProject/test in my web browser. servlet 工作,当我在我的网络浏览器中打开localhost:8080/TestProject/test时,我得到了想要的结果。 However, if I change the text in the servlet response, the changes are not reflected on the server or the front end.但是,如果我更改 servlet 响应中的文本,更改不会反映在服务器或前端。

I tried restarting the server, removing the project from the server and redeploying it, changing the server settings to "Automatically publish after a build event," enabling hot code replacement with the regex pattern \.jar$|\.class$ , and even restarting my computer.我尝试重新启动服务器,从服务器中删除项目并重新部署它,将服务器设置更改为“构建事件后自动发布”,使用正则表达式模式启用热代码替换\.jar$|\.class$ ,甚至重新启动我的电脑。 In every case, the changes are not reflected on the server or the front end unless delete the project and recreate it from scratch with the desired changes.在任何情况下,更改都不会反映在服务器或前端,除非删除项目并使用所需的更改从头开始重新创建它。

I discovered another workaround which involved shutting down the server, exporting the project from Eclipse as a WAR file, deleting the contents of the server's standalone\deployments directory, then extracting the contents of the WAR file to the same directory before turning the server back on again.我发现了另一种解决方法,它涉及关闭服务器、将项目从 Eclipse 导出为 WAR 文件、删除服务器的standalone\deployments目录的内容,然后在重新打开服务器之前将 WAR 文件的内容提取到同一目录再次。 This approach works but is highly inconvenient and impractical.这种方法有效,但非常不方便且不切实际。

I believe there is something wrong with my setup because redeployment should be much easier than this.我相信我的设置有问题,因为重新部署应该比这容易得多。 At the same time, I created the dynamic web project using the default settings, so I cannot see how it does not work.同时,我使用默认设置创建了动态 Web 项目,所以我看不出它是如何工作的。

How can I practically redeploy my project to the server?我如何实际上将我的项目重新部署到服务器?

"Automatically publish after a build event" implies that you build , ie leave automatic builds on, to deploy updated class files. “在构建事件后自动发布”意味着您构建,即保留自动构建,以部署更新的类文件。 This is also not specific to WildFly servers.这也并非特定于 WildFly 服务器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM