简体   繁体   English

启动嵌入式Tomcat并从命令行打开浏览器

[英]start embedded Tomcat and open browser from command line

I have a java web app that uses embedded Tomcat. 我有一个使用嵌入式Tomcat的Java Web应用程序。 I'd like users to open it by executing a single .bat file (Windows). 我希望用户通过执行一个.bat文件(Windows)来打开它。

I use this line for starting Tomcat: 我使用以下行来启动Tomcat:

java -cp "%cd%\apache-tomcat-8.0.8-embed\*;%cd%" Main

(main.java starts Tomcat) and if I put this line next, it won't be executed unless I manually stop Tomcat (Ctrl+C): (main.java启动Tomcat),如果我将这一行放在下一行,除非手动停止Tomcat(Ctrl + C),否则它将不会执行:

start http://127.0.0.1:8080/

If I open the browser first, and start Tomcat after that, then the users will see an error message from the browser for some seconds (while tomcat starts), and they'll panic ;) 如果我先打开浏览器,然后再启动Tomcat,那么用户将在几秒钟内从浏览器中看到一条错误消息(当tomcat启动时),他们会惊慌;)

Is there a way to return the focus to the script once Tomcat has started?, or some other workaround for this? 一旦Tomcat启动,是否有办法将焦点返回到脚本?或者其他解决方法?

In other similar threads, I saw that they could accomplish this, but they were starting tomcat by executing a Tomcat.exe file, which is not my case, since I need to use this embedded version of Tomcat, and start it the way I'm starting it. 在其他类似的线程中,我看到他们可以完成此任务,但是他们正在通过执行Tomcat.exe文件来启动tomcat,这不是我的情况,因为我需要使用此嵌入式版本的Tomcat,并按照我的方式启动它。我开始了

The best case scenario would be if I could display a temporary page saying "please wait..." while Tomcat is starting, and when it's done, show my app's initial page ( http://127.0.0.1:8080/ ) 最好的情况是,如果我可以在Tomcat启动时显示一个临时页面,说“请稍候...”,完成后,显示应用程序的初始页面( http://127.0.0.1:8080/

Any help will be really appreciated 任何帮助将不胜感激

If I understand you correctly, you can simply start java with the start command without interrupting the execution flow of the script. 如果我理解正确,则可以简单地使用start命令启动java ,而不会中断脚本的执行流程。 In other words, the script doesn't wait for the java process to end before executing the next command. 换句话说,脚本不会在执行下一个命令之前等待java进程结束。

start java -cp "%cd%\apache-tomcat-8.0.8-embed\*;%cd%" Main

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

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