I have a Windows service that executes a .bat file. This .bat file executes some Sava code that reads some files' information. The files I need to access are not in the same machine that the service is running. So I should access them using a mapping like G:\.
Even if the files exist on G:\ when I run the service, File exists() and File canRead() always return false.
If I execute the .bat manually, everything works great, but I need to execute it using a service.
The service is running with a user that has permissions to read all files on this G:\ mapping.
Does anyone have a clue as to what can be wrong? Why can't I access these remote files, when running as a Windows service?
The OS in question is Windows XP.
The problem usually is that the user running the service does not have the same G: drive as well as the same access.
I suggest you log in as the user running the service and see what that user sees.
Drive mappings aren't shared between sessions, and service sessions don't get drive mappings reestablished automatically the way interactive sessions do. You should put a net use command in the batch file to explicitly establish the drive mapping in the service session.
Related
I've some shared folders on one machine and my app(built with Java) on another machine writes some files to them. For some reason, when running the app as service I'm getting file related exceptions, but the same is working fine when the app is invoked from command line as an administrator. I even tried changing the logon role of my service to "Administrator" but that didn't help. All the shared folders' permissions seem correct as well. Any clues on what is going wrong?
For the life of me, I can't figure out what to give Java Security as a "URL" to unblock an application launched by a JNLP file in my own file directory.
When I use my browser to call the JNLP file from a Java EE application deployed to my glassfish server, I have a "URL" so I can unblock that.
But for testing I'd like to be able to also just double click the JNLP file in my local PC directory to launch the app.
It can't be that difficult. Double clicking the JNLP file does in fact begin to launch the app. Just Java blocks it. And I just can't figure out how to unblock that kind of call ... and can't find any reference to that simple a need.
Have you tried:
file:///path/to/application.jnlp
?
I have a heavy java web application that has a module which needs to be run as soon as computer starts and 24X7. That module has a bat file to execute which fetches data from server.
I want to run that bat file as a windows service on my system (OS: Windows 7)
I created service with sc create command which successfully created. But when I try to start it, it always give error 1053 i.e. can't start service ; service does not respond correctly or in timely manner.
I followed all the related threads on stack overflow and others as well but no luck.For eg., I set servicesPipeTimeout also but it doesn't work.
Is there a way in java itself to create windows service?
I do not want to use any third party like wrapper, NSSM etc or Time Scheduler either.
Please provide me some clues if anybody faced this error and get it resolved.
Thanks in advance.The time you give means a lot to me. Thanks a lot
What you are trying will not work. While SC will not tell you otherwise, it should only be used to install a binary executable that is already a "true" windows service. Because the batch file does not implement the windows services interface, it fails with error 1053 ("The service did not respond to the start or control request in timely fashion") when you try to start the service.
To start your batch file as a service, use a "service wrapper" -- an executable that implements the windows services interface and can launch your batch file when you start the service. Microsoft's SRVANY is free and basic, but there are also commercial applications more suitable for a professional environment.
I wrote a RESTful web service using Jersey library and in order to respond to the request I have to read a text file in local file system. C:\data.txt. The servlet works fine when I run it with tomcat on my own laptop.
But when I deploy the war on another machine running windows server OS and place the data.txt again at C:\data.txt. The servlet can't locate the file correctly. Anyone has idea about why is this?
Thanks a lot!
Check whether the Tomcat server process has read-access rights to file C:\data.txt. Check which user is used for running the tomcat process and check the corresponding user file permissions.
I also suspect it is a security error. Applications are usually restricted to reading and writing within their own directory under $TOMCAT_HOME/webapps. If this is the case, you need to change $TOMCAT_HOME/conf/catalina.policy to allow you to access other directories.
If you don't need to write to the file, consider moving its location inside of the classpath by putting in into $TOMCAT_HOME/lib instead.
I think this approach is also better in regards to being cross-platform.
i am writing a standalone java app. the app's properties should be configurable from a webpage deployed with the app. how do i achieve this ?
Thanks in advance
note: the app has an embedded HTTP client/server module. it should only run from command prompt
I don't think that's a good idea. Webpage forms are designed to work with a server, not with a standalone client app. You could have the app run its own web server, but that would mean the app has to be running for the configuration page to work, and it's also a rather contrived setup just to do some configuration.
It might be possible for the webpage to contain JavaScript that writes to a local file - I don't know enough about the JavaScript security model to say.
But why not have the configuration dialog as part of the app's GUI? That's the normal and expected behaviour - you'd need a pretty compelling reason to deviate from it.
JMX might be the answer that you're looking for. If you expose all of your configurable properties through MBeans, then adding a web page on top of that exposing these properties is just configuration.
You can launch a standalone Java app using JNLP files (Java WebStart). If you want the user to be able to configure the application before its launched, you can have the JNLP file dynamically generated, then pass properties as environment variables through the JNLP file.
You can configure your standalone Java app to read configurable properties from a properties file (say conf.properties) on the server.
You may have a UI webpage (html/jsp) with all the field to be configured. When the page is submitted a JSP/Servlet may write/update the contents of conf.properties on the server.
UPDATE: The above solution will work assuming only an admin user wants to update the properties file.
In case anybody should be able to update it, then concurrency issue has to be taken into account.
In that scenario, you have to implement a mechanism similar to how weblogic10 updates config.xml using Admin Console.
i.e. You will have 2 conf.properties files confA & confB (initially in sync). The standalone app will always read from confB. The UI will have 2 buttons say Lock & Release configurations. When an edit is made (locked & released), it will be written to confA and at the same time changes of confA has to be replicated to confB.