gpt4 book ai didi

java - 如何以编程方式关闭 WAR/EAR

转载 作者:搜寻专家 更新时间:2023-11-01 00:56:37 25 4
gpt4 key购买 nike

有没有办法以编程方式停止 WAR/EAR?

如果在启动/配置过程中出现问题,我需要停止应用程序部署。

如果可能,解决方案应该是跨服务器兼容的,因为我们的应用程序必须在 JBoss AS 7 和 Websphere 7/8 中运行。

目前该应用程序无法在 JBoss 上启动,它在部署过程中会出现未知错误,并且加载程序不会在部署时消失。在 Websphere 上,应用程序启动,尽管它从配置中启动了一些错误

看起来虽然我正在销毁我的 ServerHttpServlet,但我无法销毁 Jersey servlet。关于如何实现这个的任何想法?

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Server</display-name>
<servlet>
<description></description>
<display-name>ServerHttpServlet</display-name>
<servlet-name>ServerHttpServlet</servlet-name>
<servlet-class>com.transactionservice.service.ServerHttpServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<description></description>
<servlet-name>Jersey Servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<description></description>
<param-name>javax.ws.rs.Application</param-name>
<param-value>callers.REST_Application</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Jersey Servlet</servlet-name>
<url-pattern>/jaxrs/*</url-pattern>
</servlet-mapping>

<listener>
<listener-class>com.transactionservice.service.ServerServletContext</listener-class>
</listener>
</web-app>

callers.REST_Application

package callers;

import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
import com.exictos.callers.DEBUG_CONFIG;
import com.exictos.log4j.LoggerCommon;

public class REST_Application extends Application
{
private static final LoggerCommon logger = new LoggerCommon(REST_Application.class);

public REST_Application()
{
}

@Override
public Set<Class<?>> getClasses()
{
Set<Class<?>> classes = null;
try
{
// The available REST services
classes = new HashSet<Class<?>>();

classes.add(API_CALL_REST.class);
classes.add(API_CALL_REST_ENC.class);
classes.add(API_CALL_CONFIG.class);
classes.add(API_CALL_ABOUT.class);
classes.add(DEBUG_CONFIG.class);
}
catch(Exception e)
{
logger.error("", e);
}

return classes;
}
}

com.transactionservice.service.ServerServletContext

package com.transactionservice.service;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.exictos.exception.ApplicationLoadingException;

public class ServerServletContext implements ServletContextListener
{
@Override
public void contextInitialized(ServletContextEvent aServletContext)
{
//THIS IS JUST AS TEST EXAMPLE TO SEE IF WOULD WORK
throw new RuntimeException(e);
}


@Override
public void contextDestroyed(ServletContextEvent aServletContext)
{
System.out.println("------------------");
}
}

最佳答案

看看 JSR-88 - Application Deployment . WebSphere 快速入门 can be found here .请注意 Wildfly removed JSR-88 support .

也可以通过编程方式停止部署 with cargo .

我不太确定你想做什么,但我认为正常的方式应该是部署应用程序的人员或流程应该验证部署是否有效,如果没有,则以相同的方式取消部署。

关于java - 如何以编程方式关闭 WAR/EAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23561149/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com