File Listener Implementation using Java

I'm trying to use  FileAlterationListener, FileAlterationObserver from Apache Commons IO to listen to Files.
How do i make the  program start automatically without using "main" so that File Monitor starts once the bean is deployed on to JEE server.
prashant_eeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gurpsbassiCommented:
Can you not create an implementation of ServletContextListener? which will simply start your File Monitor.
0
prashant_eeAuthor Commented:
Thanks for your Quick Reply gurpsbassi.
Do i need to deploy the packaged application as WAR?
0
gurpsbassiCommented:
Yes, configure the listener in the web.xml or if you're using the servlet 3.0 spec then you can simply just annotate your listener class with @WebServletContextListener
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

gurpsbassiCommented:
Also when you say
once the bean is deployed on to JEE server
, are you implying this is a EJB?
0
prashant_eeAuthor Commented:
Yes, I was looking into EJB as one of the option packaged as EAR. Runtime environment is Websphere 8.0
0
gurpsbassiCommented:
You could also use a timer service for the EJB;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CEHJCommented:
Bear in mind too that the JRE has supported file watching out of the box since 1.7

https://docs.oracle.com/javase/8/docs/api/java/nio/file/Watchable.html
0
prashant_eeAuthor Commented:
@CEHI..Thanks for your Reply..
I would love to use 1.7 , but unfortunately Websphere 8.0 supports 1.6
0
prashant_eeAuthor Commented:
Straight forward solution for what i was looking for..Thank you!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.