Reputation: 1652
i have follow this tutorial to run a java class as a window service.
Java Service Wrapper HelloWorldServer Example
I did a minor changes i change the HellowWroldServer class to as follow
public class HelloWorldServer {
public static void main(String args[]) throws Exception {
PrintWriter pw = new PrintWriter(new File("D:/new.txt"));
pw.println("i have write this line in new text file");
pw.flush();
pw.close();
}
}
What this code do is simple it create a "new.txt" file in D location. I follow the rest tutorial. I didn't get any error and successfully install the window service.
Now after installation i expected when i run the window service it will create a file in the D location but i am wrong. My window service didn't create new.txt file in the D location. anyone can tell me what is the problem??
Upvotes: 1
Views: 3789
Reputation: 194
When you are running as a Windows Service, the user is by default the SYSTEM user. That user has much different permissions than the user you are logged on as. Please make sure that you actually have access.
In the application you wrote though, if this fails then you should be getting an IOException. Did you see anything in the wrapper.log file?
If you want to change the user that the service runs as, see the following page: http://wrapper.tanukisoftware.com/doc/english/prop-ntservice-account.html
I hope this helps.
Cheers, Leif
Upvotes: 1