In my java program, I am finding all the files in a
directory. When I run it as an application using a .bat
file, the code File.listFiles() ( Java) returns the list of
files. But when I run it as a service, it does not return the
files. it returns a null. I am not sure why...
Logged In: YES
user_id=228081
Most likely your current directory is not what you think it
is. The Wrapper alsways sets the current directory to the
location of the Wrapper.exe. If you are using relative
paths, everything must be relative to that location.
Try calling file.getAbsolutePath() to verify the directory
whose files you are requesting.
Cheers,
Leif
Logged In: NO
STATUS | wrapper | 2005/09/26 10:56:04 | Service is
running. Stopping it...
STATUS | wrapper | 2005/09/26 10:56:05 | <-- Wrapper
Stopped
STATUS | wrapper | 2005/09/26 10:56:06 | COLD Test
Wrapper Sample Application stopped.
STATUS | wrapper | 2005/09/26 10:56:06 | COLD Test
Wrapper Sample Application removed.
STATUS | wrapper | 2005/09/26 10:56:08 | COLD Test
Wrapper Sample Application installed.
STATUS | wrapper | 2005/09/26 10:56:36 | --> Wrapper
Started as Service
STATUS | wrapper | 2005/09/26 10:56:37 | Launching a
JVM...
INFO | jvm 1 | 2005/09/26 10:56:37 | Wrapper (Version
3.1.2) http://wrapper.tanukisoftware.org
INFO | jvm 1 | 2005/09/26 10:56:37 |
INFO | jvm 1 | 2005/09/26 10:56:37 | Dir: \\devsrv\util ->
C:\Program Files\Util\Backup
INFO | jvm 1 | 2005/09/26 10:56:37 | Files :null
Leif,
Thank for your response. Note the source directory from
where I am trying to move the files ( \\sdt-devsrv\ccutil). This
is a machine on the network where ccutil is a shared
directory and the destination directory ( C:\Program
Files\Util\Backup). When I call the listFiles() interface on the
File object that represents the source directory(\\devsrv\util), I
get the list of files if I run I as a java program from my IDE but
when I run it as a service, I get a NULL.
Here is the code that I am using. you can use this code for
testing purposes.
private static void moveDir(File src, File dst) {
System.out.println("Dir: " + src.getAbsolutePath() + " -
> " + dst.getAbsolutePath());
// Create the destination directory
dst.mkdirs();
// Loop through the files and directories in the source
directory and copy them
File[] files = src.listFiles();
if ( files != null )
{
for (int i = 0; i < files.length; ++i) {
if (files[i].isFile()) {
moveFile(files[i], new File(dst, files[i].getName()));
}
else if (files[i].isDirectory()) {
moveDir(files[i], new File(dst, files[i].getName()));
}
}
}
else
{
System.out.println("Files :" + files );
}
}
private static void moveFile(File src, File dst)
{
System.out.println("File: " + src + " -> " + dst);
boolean success = src.renameTo(dst);
}
Logged In: NO
STATUS | wrapper | 2005/09/26 10:56:04 | Service is
running. Stopping it...
STATUS | wrapper | 2005/09/26 10:56:05 | <-- Wrapper
Stopped
STATUS | wrapper | 2005/09/26 10:56:06 | COLD Test
Wrapper Sample Application stopped.
STATUS | wrapper | 2005/09/26 10:56:06 | COLD Test
Wrapper Sample Application removed.
STATUS | wrapper | 2005/09/26 10:56:08 | COLD Test
Wrapper Sample Application installed.
STATUS | wrapper | 2005/09/26 10:56:36 | --> Wrapper
Started as Service
STATUS | wrapper | 2005/09/26 10:56:37 | Launching a
JVM...
INFO | jvm 1 | 2005/09/26 10:56:37 | Wrapper (Version
3.1.2) http://wrapper.tanukisoftware.org
INFO | jvm 1 | 2005/09/26 10:56:37 |
INFO | jvm 1 | 2005/09/26 10:56:37 | Dir: \\devsrv\util ->
C:\Program Files\Util\Backup
INFO | jvm 1 | 2005/09/26 10:56:37 | Files :null
Leif,
Thank for your response. Note the source directory from
where I am trying to move the files ( \\sdt-devsrv\ccutil). This
is a machine on the network where ccutil is a shared
directory and the destination directory ( C:\Program
Files\Util\Backup). When I call the listFiles() interface on the
File object that represents the source directory(\\devsrv\util), I
get the list of files if I run I as a java program from my IDE but
when I run it as a service, I get a NULL.
Here is the code that I am using. you can use this code for
testing purposes.
private static void moveDir(File src, File dst) {
System.out.println("Dir: " + src.getAbsolutePath() + " -
> " + dst.getAbsolutePath());
// Create the destination directory
dst.mkdirs();
// Loop through the files and directories in the source
directory and copy them
File[] files = src.listFiles();
if ( files != null )
{
for (int i = 0; i < files.length; ++i) {
if (files[i].isFile()) {
moveFile(files[i], new File(dst, files[i].getName()));
}
else if (files[i].isDirectory()) {
moveDir(files[i], new File(dst, files[i].getName()));
}
}
}
else
{
System.out.println("Files :" + files );
}
}
private static void moveFile(File src, File dst)
{
System.out.println("File: " + src + " -> " + dst);
boolean success = src.renameTo(dst);
}
Logged In: YES
user_id=228081
Oh. A network drive. By default the Wrapper runs as a
service as the SYSTEM user. This user does not have the
ability to access network devices. You have to specify
another user to run as and then make sure that that user has
its network access configured correctly and set up to auto
logon without requiring any manual password input.
See the following page:
http://wrapper.tanukisoftware.org/doc/english/prop-ntservice-account.html
The listFiles method returns null when the specified
directory can not be found.
Cheers,
Leif