In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
Most people do not understand the knowledge points of this article "how to increase java startup commands for tomcat services", so the editor summarizes the following, detailed content, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "how to increase java startup commands for tomcat services" article.
Existing code:
1. Main function: maingame.java (the lead function of the game startup.)
two。 Frame run class: gameenterframe.java (responsible for loop execution, I set it to run once every 2 seconds to write numbers to the database. )
There are two key points about self-startup:
1. You need to modify a configuration file named web.xml
In web-inf under webroot.
If you don't have the same path as my picture, it's a pity that your project type has been created wrong.
Remember to new a web server project.
Simply add three lines of code to this file and tell tomcat that I'm going to run a self-starting class, and I'll name it autorun. As shown in the following figure, the blue part is the code I added.
Convenient for everyone to use, paste it out.
Game.autorun
With this listener, you can execute the autorun class under the game package (the game package is a game package I created myself, and you can create the name of your favorite package) at run time. This autorun class is the self-startup code I wrote.
How to write it, take a look at the following:
two。 How to write the self-startup code:
We need to get the self-startup code to lead to the main function. So under the game package, create a new file named autorun.java
Package game;import javax.servlet.servletcontextevent;// this is the class to be used since startup. The server background event import javax.servlet.servletcontextlistener;// is the class to be used for self-startup. The server background listens to import game.maingame;//. We import the main function to run / / declare an autorun class and use the server background listening interface. Fixed usage, rote memorization public class autorun implements servletcontextlistener {/ / when the background is initialized, the tomcat startup event occurs. The fixed usage public void contextinitialized (servletcontextevent arg0) {/ / what you need to do, write here system.out.println ("mainfunction is running."); maingame.main (null);} / / when the background is destroyed, the tomcat shutdown event occurs, and the fixed usage public void contextdestroyed (servletcontextevent arg0) {/ / execution content is written here}}
As you can see, there are two parts in monitoring the tomcat startup and shutdown state.
One is to start. What am I going to do?
The other is closed. What am I going to do?
Of course, it's off. I don't need to do anything right now. I just need to execute the main function of the game after startup. So I left the main function in the startup.
The above is about the content of this article on "how to add java startup commands to tomcat services". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.