This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Another newbie here I'm slowly making the change from VB orientated scripting (VB6, vbs, vba, etc) to Java. I'm trying to achieve something, and I'm not sure I'm going the right way about it.
I've built an IR blaster and trapped the signals I need, to turn my air con ON and OFF. I can call these signals from a batch file (eg. "irblast.exe ac_on.IR"). This works fine. What i've done next is write some PHP code to save a file to my webserver when I log on to my website and submit the text "ac=on", from a regular html form. The result is a file on my webserver called aircon.status, containing the word "ON". I've then written some JAVA code to check the file exists, read the file and run the batch file ac_on.bat or ac_off.bat (depending on whether the file contains the word ON or OFF). This all works fine, but now I'd like the Java code to run as a service, so it's always running and continues to check the existance of the aircon file. I'm currently looking at YAJSW http://yajsw.sourceforge.net/. I havn't finished configuring it all yet, but....am i approaching this logically the right way? Is there an easier way to have a java program run, checking every 5 minutes or so the existance of an online file and running a batch file based on what's contained in the file?
I'd appreciate ANY guidance at all. I'm really new to the world of Java, and knowing me I'm going the long way around something that is probably very simple to achieve.
I only read the first few words of your post and though, "no you aren't."
Start small. Even things like "for" loops in Java are slightly different from other languages, so you can hide some dangerous misconceptions from yourself by starting with a big project. Beware of batch files and services. They tie the code to a particular platform (in that case Windows).
At least that's my opinion
Joined: Jul 29, 2009
Thanks for the reply. I've been working through a bunch of lessons. Getting familiar with all the basic. So far so good. Although it is a pretty big learning curve . I've managed to use the wrapper to create the service. However I can't seem to start the service. I might post a new thread in the applicable section of the forums.
It'd be easiest to redo the web service in Java as a servlet (using Tomcat, for example) and then include a scheduled job in the servlet container which did the checking and signaling. Actually, it'd be easiest to have the servlet directly kick off the IR signal, but perhaps that's too open to abuse.
Well I've done some reading RE servlets and this would have been perfect! Unfortunately I had to pay for external web hosting as my ISP doesn't allow inbound port 80, and we block all but inbound port 80 at work. Rendering my web server's configuration (on another random port) useless. I will definitely be looking into servlets though for possible future use (perhaps when I shift to a more reasonable ISP).
Thanks for your suggestions.
Joined: Jul 29, 2009
Just to let anyone interested know, I got the service to start using yajsw. I had to manually configure the account (and password) to run the service under. For some reason the configuration file didn't apply correctly. Everything's working nicely now.