General J2EE: How to load/start a class with a main method inside an EAR file
Hi. I have a J2EE application deployed in a JBoss 3.2.5 server. As part of this application, I have a piece of code that needs to constantly run in the background waiting for some sort of "signal" to do some processing. This signal comes from an EJB inside my J2EE application. After analyzing my choices, I concluded that this code is not well-suited to be an EJB or a servlet. Instead, it makes more sense to have it running as a standard Java "main" application, waiting for either a socket or JMS message as the signal. However, I don't want to have this piece of code running in a separate JVM window, since it's part of my J2EE application anyway, having both of them exactly the same life cycle.
- Posted by: Aldo Laiseca
- Posted on: September 11 2004 18:43 EDT
The question is: does J2EE/JBoss provide something to make this kind of Java "main" applications to be loaded and started automatically as part of a J2EE application? If I deploy both the Java "main" application and the J2EE components inside the same EAR file, how can I tell J2EE/JBoss to also load and start the class or classes having a main method? Thank you very much in advance.
- How to load/start a class with a main method inside an EAR file by josef betancourt on September 11 2004 21:56 EDT
- How to load/start a class with a main method inside an EAR file by josef betancourt on September 11 2004 22:08 EDT
- How to load/start a class with a main method inside an EAR file by Aldo Laiseca on September 12 2004 02:44 EDT
- Create a servlet that starts your class via main by Neil Morrison on September 12 2004 03:21 EDT
- Try JMX by Ilgvars Jecis on September 13 2004 06:08 EDT
Why not have that signal just invoke a message bean? That is the primary way of doing asynch stuff in j2ee app server, afaik.
-- J. Betancourt
Oops. Reread your message, JMS won't help, and you mentioned it already. :)
There are some systems that run inside a j2ee 'app'. For example, Quartz, see http://www.opensymphony.com/quartz/. Quartz in response to an event does scheduling stuff, yours will do other stuff. Note, I'm not indicating to use Quartz for this, but as an analogous scenario perhaps.
The problem is that I need to process a file in the local filesystem (previously uploaded by an Internet client). AFAIK it's not possible to access the filesystem within a EJB, so I have to implement the process as a standard Java application.
Can you not create a servlet that calls your main method.
Override the init() method in the servlet and set the servlet to auto-start. Not sure if JBoss can autostart servlets assume it does as WebSphere does.
You should try JMX MBean. Perhaps you can do something in start() method of MBean (start listening thread or something else...)