Monitor Directory with Java Web

Asked

Viewed 145 times

0

I’m working on an application Java Web, using the server Apache Tomcat and I need to monitor, or "listen" to a directory on the server. Asynchronously, and permanently. Because when a file is created in this directory, I need to examine and move it to the correct directory.

I even managed to use the Watch Service API, but I was able to work only for a local java application (jar).

Is there a possibility of using for web? Or is there any other way more effective?

  • I do not know your case but I am having problems when I start the watch I need to make changes to the look and this does not happen even my application does not close after active. I’m looking for a solution but without success.

  • @Devagil can post better details of the problem or the same code?

  • 1

    Follow the link of my question http://answall.com/questions/116281/directmonitoring%C3%B3rio-do-the-stop-system-to-respond%C3%A7%C3%B5es

1 answer

1


Watch out for the Java version

Yes, you can use it for a web application Yes, no problem, even because you are on the Java SE platform. Just keep in mind that the Java version, you should use at least version 1.7 of the platform. Then check if the Web server or EE is working with this version of Java. Depending on the Tomcat version, you may not be able to use it.

The Watch Service is very powerful, should suit you perfectly.

  • Cool @Filipegonzagamiranda, and how can I leave it running permanently after deploy? I need to use threads?

  • 1

    Ai depends a lot on the design of your application, really it is difficult to tell you in cold. For example, I don’t know if you will be using Ejbs, other frameworks. Finally, what I would recommend is vc Startar the service in Init of your Mapped Servlet in Web.xml, putting a Thread there, but again, it is very difficult to say without having all the details in hand. And of course different solutions and approaches can emerge. I would start thinking about Servlet init

  • I believe that Servlet’s Init helps, is a simple web application (Servlet) even, just for the purpose of monitoring a directory, analyze the files and move to the destination directory. No EJB or other frameworks. Thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.