First of all, the topic is a pseudo-proposition, the JBoss container is not supported directly deploy executable jar package, jar will only be loaded as Lib treats. A small workaround is provided here.
Today, I have a problem, the monitoring module in our project to separate into a small project deployment, monitoring logic is relatively simple, the implementation of this small project only rely on some common jar and spring JdbcTemplate.
So I always don't want to make the deployment too complicated, directly write the main () Portal deployment jar is ideal. However, as above, JBoss does not support.
can only be transformed into a Web project to fight the war package, in the tangled with which framework to implement Servet monitoring and start the entrance, brainwave, why not write a servletlistener.
Let's start by changing the project to a web structure, and then start implementing a servlet listener, which is as simple as inheriting servletcontextlistener, and then pasting the boot code into contextinitialized.
public class StartMonitor implements servletcontextlistener{
@Override
public void contextinitialized (Servletcontextevent sce) {
This writes the original executable jar's Main method logic
}
@Override
public void contextdestroyed (Servletcontextevent sce) {
}
}
Configure the Listener in Web. Xml., everything is done. You can run the war package.
<web-app>
<listener>
<listener-class>
${pakagepath}. StartMonitor
</listener-class>
</listener>
</web-app>
Looking back, in fact, this solution is very common, just because I smattering the operation of the servlet container, always feel that running a web must be inseparable from the spring listener that similar things, to introduce many components and so on. But in essence, the servlet itself is very concise? Just provide a range of standard interfaces for third-party extensions (such as listener), and anyone can implement these interfaces as needed.
Further, the components commonly used in the Web struts2, spring,spring MVC is just an implementation of the Servlet standard interface based on experience?
Because the novice first contact is a variety of frameworks, but it is easy to ignore the most basic principle. I'd like to remind you!
Deploying the executable jar in JBoss, the Deploy executable jar in JBoss