[英]Standalone application inside tomcat
I have a simple java class that i want to run programmatically. 我有一个想以编程方式运行的简单Java类。 This is basically a video player. 这基本上是一个视频播放器。 It is also deployed along with my web application in tomcat. 它还与我的Web应用程序一起部署在tomcat中。 This should run upon a click on a particular link. 这应该在单击特定链接时运行。 From controller, here's how I run it 在控制器中,这是我的运行方式
new Thread(() -> { VideoPlayer.main(new String[]{}); }).start(); new Thread(()-> {VideoPlayer.main(new String [] {});})。start();
It is working fine. 一切正常。 But every time I close the Video player, tomcat is also terminated. 但是每次关闭视频播放器时,tomcat也将终止。 Any ideas on how to correct this? 关于如何纠正这一点的任何想法?
Your GUI probably calls System.exit
when you close it. 关闭它时,GUI可能会调用System.exit
。 That'll take-down Tomcat since they are both running in the same JVM. 这将删除Tomcat,因为它们都在同一个JVM中运行。 Find and remove the System.exit
and you'll find things work-out better for you. 找到并删除System.exit
,您会发现事情对您而言更好。
Also note that it doesn't make any sense for a web application to launch a video player. 另请注意,对于Web应用程序而言,启动视频播放器没有任何意义。 Think about it: once the web application is no longer running on your own personal development workstation, the video will be played on the server where there isn't anyone to watch it. 想想看:一旦Web应用程序不再在您自己的个人开发工作站上运行,该视频将在没有人观看的服务器上播放。 The server probably won't even have a monitor attached to it. 服务器可能甚至没有连接监视器。 Most likely, you'll get a whole series of exceptions from the video player telling you it couldn't initialize itself because there isn't any graphics environment in which to start. 最有可能的是,视频播放器会提供一系列异常,告诉您它无法初始化,因为没有任何可在其中启动的图形环境。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.