4

I just moved applications from WindowsXp to Windows7. I run several applications through the Eclipse run configuration manager setup.

Most of the applications access a samba mount/network drive using the UNC path. With this approach, the path shows up as "directory does not exist". If I run the application from within Windows explorer, the application runs fine.

I am sure this is related to Windows7 new security model. I was just curious if there is way to run my application like I did with WindowsXP.

Here is an example approach:

new File("\\\\myserver\\myFile.txt").exists();`

If I run the code from a main application through Eclipse, it will return "true" on windowsXP and false on windows 7.

I need it to exist for windows 7.

INSIDE OF ECLIPSE, THIS DOES NOT WORK. But running OUTSIDE OF eclipse, say through windows explorer, it works fine. Also, Eclipse is running as administrator.

Berlin Brown
  • 11,504
  • 37
  • 135
  • 203
  • 2
    I think it should be `new File("\\\\myserver").exists(); ` double-backslashes are required for backslashes in the path. – ee. Mar 02 '12 at 03:07
  • I suggest you to create a Windows network drive where you can provide user:password as follows in the link: http://stackoverflow.com/questions/208839/how-can-i-mount-a-windows-drive-in-java – ee. Mar 02 '12 at 03:19
  • ee, that was sort of pseudo code. I left out the exact UNC path. This has more to do with the networking and security related to Windows7. I was trying to avoid changing the actual code but looking to see if there is a setting for Windows7 or a flag I can pass to Eclipse that would allow me access to those paths. – Berlin Brown Mar 02 '12 at 03:32
  • 1
    Of course it is Windows 7's User Access Control (UAC) which does not present in Windows XP. So, I suggest a workaround using `net use` tool to create a Windows network drive for that UNC path with proper user:password setup. – ee. Mar 02 '12 at 03:39
  • I can launch the application outside of Eclipse and it works fine. What is it about Eclipse that doesn't allow this application to run. – Berlin Brown Mar 02 '12 at 04:29
  • 2
    This could probably be a problem with the user-rights you run eclipse. Have you tried to launch it as administrator? I don't know how exactly the UAC works, but I solved such problems often by launching the application as admin ;) – Benni Mar 05 '12 at 10:31
  • Are you actually looking for `\\myserver` or `\\myserver\folder`? – stryba Mar 08 '12 at 20:50
  • Yea, I ran this as administrator – Berlin Brown Mar 13 '12 at 14:03

2 Answers2

1

Yes, you are right. While executing new File("\\myserver").exists(); it returns false. These are the points i noted when I tried this on my windows 7 machine.

  1. Like the others said, you should use \\\\ (double slashes) to represent back slashes in java
  2. new File("\\\\myserver").exists(); also returns false. This is because, you are trying to access a network drive using File IO.
  3. Suppose there is a file or directory on on myserver, say myFile.txt or another directory myDirectory. Then if you access any of the file/directory, then it returns true.

    new File("\\\\myserver\\myFile.txt").exists();
    new File("\\\\myserver\\myDirectory").exists();
    The above lines returns true

UPDATE: \\myserver can be accessed only on interactive programs like GUI applications, but not programmaticaly. Although JCIFS is another alternative to access network drives.

Rakesh
  • 4,264
  • 4
  • 32
  • 58
  • It works fine OUTSIDE OF ECLIPSE. I can run the application without error. When I run the application as a main application from within Eclipse (say through run configurations) the application does not run, those directories do not exist. The issue is with Eclipse. I might need to use a mounted drive but I am not using a new FS connection. – Berlin Brown Mar 13 '12 at 20:47
  • The same thing runs as expected on xp ? – Rakesh Mar 14 '12 at 06:11
  • XP does not have this issue. Only on Win7 – Berlin Brown Mar 14 '12 at 14:41
1

First of all, you need to escape any backslash with another, because the backslash is a special use char in strings. So you would do new URI("\\smbServer") to correspond to \smbServer typed in the windows address bar.

Second of all the samba base mountpoint is not a folder, which is why you can't open it with io. You need to mount it as a Samba mountpoint in a special class, or let the windows drivers resolve it for you by trying to access a folder within it.

Gepsens
  • 673
  • 4
  • 14
  • but this would contradict with the OPs statement: "If I run the application from within Windows explorer, the application runs fine" – stryba Mar 09 '12 at 22:40