1

I have a program where I actively ping the contents of a directory using nio.WatchService.

Anytime a new file is added there, I process some custom logic. The path to the folder is read from a properties file and has the following format:

pathvar=C:\\files\\in\\ -->works on local
pathvar=\\\\serv123\\Share\\input\\ --> works on local

Both formats run fine on win 7 local (command line and through IDE). When executed on a win 2008 R2 server, the program executes when path variable is local - no (mapped) network paths work.

pathvar=C:\\\\files\\in\\ -->works
pathvar=\\\\serv123\\Share\\input\\ --> does not work
pathvar=N:\\Share\\input\\ --> N: mapped to serv123 does not work

Code is same as listed here:Watching a Directory for Changes in Java

I don't get any exceptions either, but UNC paths are not working. Any help is appreciated.

Edit: The way I deducted the issue was path related(in absence of any exceptions), is by playing around with the paths.

I packaged it as a jar and run it on the command window as

java -jar myjar.jar

With pathvar=C:\files\in\, the programs runs and waits With pathvar=\\server\files\in\, it quits immediately/

Community
  • 1
  • 1
sujith
  • 11
  • 1
  • 4
  • File watch code in Java relies on the operating system. Most of the time, operating system watch facilities will only notify you of changes on file systems that are local to the machine. – BillRobertson42 Jun 11 '15 at 15:45
  • @Bill Isnt there a more consistent fix for that? The program runs fine accessing network drive from my pc. Could it be some port/permission related? Weirder thing is, Im only having trouble reading, I can do Files.move() fine. – sujith Jun 11 '15 at 16:06
  • AFAIK it's an issue with supporting Window's UNC naming scheme across other operating systems. i.e. it's platform specific – BillRobertson42 Jun 11 '15 at 16:39
  • You might find this previous query useful: http://stackoverflow.com/questions/18520972/converting-java-file-url-to-file-path-platform-independent-including-u –  Jun 11 '15 at 23:44
  • yeah, it doesn't work on all file systems. see also http://stackoverflow.com/questions/8476419/java-watchservice-not-generating-events-while-watching-mapped-drives – ZhongYu Jun 11 '15 at 23:56
  • just scan the directory periodically :) – ZhongYu Jun 11 '15 at 23:57

0 Answers0