简体   繁体   English

从Web存档执行命令

[英]Execute Command from Web Archive

I included a scheduled job in my WAR file through Quartz and Spring. 我通过Quartz和Spring在WAR文件中包含了计划的作业。 In case that the scheduled job misses, I have to execute a method Class_A.Method_A() explicitly. 万一计划的作业错过了,我必须显式执行方法Class_A.Method_A()。

In order to execute the method, I plan to create a static method main() under Class_A so that I can execute jar -cp $CLASSPATH Class_A. 为了执行该方法,我计划在Class_A下创建一个静态方法main(),以便我可以执行jar -cp $ CLASSPATH Class_A。 However, the class is inside the WAR file, how can I do it? 但是,该类位于WAR文件中,该怎么办?

In addition, the WAR file has its data source and log4j configuration and the method Method_A does database access and logging through them, if I call it on command prompt, is there any conflict? 此外,WAR文件具有其数据源和log4j配置,并且Method_A方法通过它们进行数据库访问和日志记录,如果在命令提示符下调用它,是否有冲突?

If calling it through a comamnd prompt is not a good practice, what is a better way? 如果通过命令提示符调用它不是一个好习惯,那么有什么更好的方法? Please help. 请帮忙。

Why are you trying to execute 'jar -cp'. 为什么要尝试执行“ jar -cp”。 This will be a separate jvm execution and hence you will not be able to directly access the resources in the jvm running the web application (this means objects spawned in the jvm's memory space by the web application). 这将是单独的jvm执行,因此您将无法直接访问运行Web应用程序的jvm中的资源(这意味着该Web应用程序在jvm的内存空间中产生了对象)。 [This is answer to your question about conflict/ [这是您关于冲突的问题的答案/

Please mention what application server on which your web application is running. 请提及您的Web应用程序在哪个服务器上运行。

Seeing your comment about System Administrator (though I would have mentioned this regardless of this as well). 看到您对系统管理员的评论(尽管无论如何我也会提到这一点)。 Have you ever heard of ServiceMBeans, you can try them. 您是否听说过ServiceMBeans,可以尝试一下。

Your scenario is a very generalized scenario, where people need to access a particular class (better say instance of the class) running inside a JVM. 您的场景是一个非常笼统的场景,人们需要访问在JVM中运行的特定类(最好是该类的实例)。 You certainly need something which loads up along with the application. 您当然需要与应用程序一起加载的内容。

You can write a Service MBean to run along (inside) your web application. 您可以编写Service MBean以便在您的Web应用程序中(内部)运行。 This would mean you are exposing action. 这意味着您要公开动作。 Then you can write a java client to interact with the MBean and make call to its exposed methods. 然后,您可以编写一个Java客户端与MBean交互并调用其公开的方法。

In case your application server provides authentication for accessing MBeans. 如果您的应用程序服务器提供访问MBean的身份验证。

Other option is JMS implementation. 另一种选择是JMS实现。 Setup a JMSQueue, whose listener will execute the action interacting with the classes of web application. 设置一个JMSQueue,其侦听器将执行与Web应用程序类交互的动作。 Obviously the listener would load along side web application. 显然,侦听器将随侧面Web应用程序一起加载。 EJB implementation would allow you to load the listener via simple ejb xml or through annotations. EJB实现将允许您通过简单的ejb xml或注释来加载侦听器。

Then you write up a separate java code which can send message commands to the JMSQueue. 然后,编写一个单独的Java代码,该代码可以将消息命令发送到JMSQueue。 All application server provides the option of authentication. 所有应用程序服务器均提供身份验证选项。

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

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