WinRun4J 0.3.3 Released
A new version of WinRun4J is available. It contains the following fixes and new features:
- Moved service name, description and controls accepted to INI file
- Refactored Service interface and added AbstractService helper class
- Implemented FileAssociations helper class
- Greatly improved the Registry API
- Option to log to console and file
- Log file rolling
- Fix for relative log file path
The Registry API has been refactored to be easier to use (no need to open/close).
The Service API is now also much easier to use, with an AbstractService class. This makes the example service implementation much simpler:
package org.boris.winrun4j.test;
import org.boris.winrun4j.AbstractService;
import org.boris.winrun4j.EventLog;
import org.boris.winrun4j.ServiceException;
/**
* A basic service.
*/
public class ServiceTest extends AbstractService
{
public int serviceMain(String[] args) throws ServiceException {
int count = 0;
while (!shutdown) {
try {
Thread.sleep(6000);
} catch (InterruptedException e) {
}
if (++count % 10 == 0)
EventLog.report("WinRun4J Test Service",
EventLog.INFORMATION, "Ping");
}
return 0;
}
}
The shutdown variable is set to true when the service is requested to close by the service control manager.
You can download the new version from the WinRun4J Sourceforge Site.










nielm 10:53 am on June 19, 2009 Permalink |
Thanks for creating this — it’s a very useful tool.
One small point about the log.file.and.console setting – - I did not realise that it was only for WinRun4J logging, (and java logging via the ‘Log’ class). I had assumed that all stdout/stderr was redirected to both destinations (similar to Unix’s Tee: a very useful tool!), and spent ages trying to figure out why it was not working!
poidasmith 9:47 am on June 20, 2009 Permalink |
Yes, this is a good point. I’ll update the documentation to point this out for the moment.
Kirill 9:04 am on October 15, 2009 Permalink
I proud that I also took a part in winrun4j logging! (log & log.overwrite options
jaking 3:26 pm on July 6, 2009 Permalink |
Hi,
First of all thank you for this great tool, it is very intuitive.
I am currently evaluating this tool along with “Java Service Wrapper” and I have encountered a problem when setting up a service with JRE packaged with the application
I have the following ini setup:
vm.location=jre/bin
service.class=org.boris.winrun4j.test.ServiceTest
service.id=ServiceTest
service.name=WinRun4J Test Service
service.description=An example service using WinRun4J.
classpath.1=*.jar
When I try to launch the service I get the following error:
[info] Module Name: D:\service\winruntest\service.exe
[info] Module INI: D:\service\winruntest\service.ini
[info] Module Dir: D:\service\winruntest\
[info] INI Dir: D:\service\winruntest\
[info] Found VM: D:\service\winruntest\jre\bin
[info] Expanding Classpath: *.jar
[info] Expanding Classpath: D:\service\winruntest/WinRun4J.jar
[info] Expanding Classpath: D:\service\winruntest/WinRun4JTest.jar
[info] Generated Classpath: D:\service\winruntest\WinRun4J.jar;D:\service\winruntest\WinRun4JTest.jar
[info] VM Args:
[info] vmarg.0=-Djava.class.path=D:\service\winruntest\WinRun4J.jar;D:\service\winruntest\WinRun4JTest.jar
[info] Main Class: org/boris/winrun4j/test/ServiceTest
[err] ERROR: Could not load library: D:\service\winruntest\jre\bin
[err] Error starting Java VM
Am I missing something?
Thanks
jaking 4:29 pm on July 6, 2009 Permalink |
Hi,
Problem solved by replacing jre/bin witj jre/bin/client/jvm.dll
poidasmith 7:30 pm on July 6, 2009 Permalink
Admittedly its a little unclear that you need to point to the DLL. I’ll update the website docs to make it more explicit.
poidasmith 7:31 pm on July 6, 2009 Permalink
BTW, let me know how you get on with your evaluation. I’d be interested to hear what differences you found and pros/cons between the two.
jaking 11:12 am on July 14, 2009 Permalink
Hi,
While evaluating WinRun4J and JSW I was left with the following impressions (so far):
1) I found both solutions very easy to setup and get started, but WinRun4J felt much “cleaner” to deploy and configure.
2) JSW was alot more helpful in those situations where it holds control by providing logging info.
E.g. if the service can´t start because the path to an embedded jvm is incorrect, JSW informed me of that fact while WinRun4J left me guessing.
3) This point is more of a question than an opinion since I experienced a JVM “crash” with JSW and not with WinRun4J.
First, so that there is no confusion, I know for a fact that the crash was not due to a JSW issue.
My question is: JSW made it possible for my app (service) to recover from the JVM crash, how would WinRun4J react in the same situation (JVN crash)? Do we need to include any measures as a precaution?
For now I am not going to leave any humble Overall… sentences, but, I am enjoying this excellent tool and I will be using it!!!
Thanks again for this great tool.
poidasmith 7:40 pm on July 15, 2009 Permalink
Hi,
Thanks for the feedback!
Certainly the logging could be improved to provide the user with more pertinent information on failure.
WinRun4J doesn’t do anything clever around restarts etc.. I have a todo to detect when the JVM hangs and report this and react (possibly shutdown). I just have to find a rock-solid way of detecting a hang… As for restarting its certainly possible (if a little clunky) but I imagine native services don’t have this feature because the service control manager does (eg. restart on first failure, second failure etc.. – see the recovery tab on the service properties).
Regards,
Peter
jaking 2:04 pm on July 15, 2009 Permalink |
I setup a small test to launch an application with the following .ini file and corresponding exe file:
vm.location=../jre/bin/client/jvm.dll
vm.version=1.6.0_11
classpath.1=../lib/*.jar
working.directory=.
main.class=some.domain.topic.Main
When I launch the app using the exe file, I noticed that the correspoding command window was also launched.
If WinRun4J “is an alternative to javaw.exe”, why is there a corresponding command window when the app is launched.
I don’t see anything in the ini keys that i could use to prevent this.
Am I missing something?
poidasmith 7:41 pm on July 15, 2009 Permalink |
Hi,
Are you perhaps using the WinRun4Jc.exe (ie the console version of the launcher)? This will cause a console to appear if it isn’t run from an existing console. If you want the same behaviour as javaw.exe you need to use WinRun4J.exe.
Regards,
Peter
jaking 8:41 am on July 16, 2009 Permalink
Hi,
Yip, I was using WinRun4Jc.exe – changed it for WinRun4J.exe and no command window appears.
Thank you
weishaupt@bernot.net 7:57 am on July 24, 2009 Permalink |
Hi,
I still have problems running WinRun4j version 0.3.3 as windows service (WinXP SP2 German) .
1 (critical): start and stop service manually runs fine. But if I logoff the user from windows – the service crashes hard. After login the service isn’t running – no log message – nothing.
2: running your TestServiceArgs produces the following log:
[info] Module Name: D:\downloads\winrun4J-0.3.3\winrun4j\bin\service\service.exe
[info] Module INI: D:\downloads\winrun4J-0.3.3\winrun4j\bin\service\service.ini
[info] Module Dir: D:\downloads\winrun4J-0.3.3\winrun4j\bin\service\
[info] INI Dir: D:\downloads\winrun4J-0.3.3\winrun4j\bin\service\
[info] Working directory set to: D:\downloads\winrun4J-0.3.3\winrun4j\bin\service
[info] Found VM: C:\Programme\Java\jre6\bin\client\jvm.dll
[info] Expanding Classpath: *.jar
[info] Expanding Classpath: D:\downloads\winrun4J-0.3.3\winrun4j\bin\service/WinRun4J.jar
[info] Expanding Classpath: D:\downloads\winrun4J-0.3.3\winrun4j\bin\service/WinRun4JTest.jar
[info] Generated Classpath: D:\downloads\winrun4J-0.3.3\winrun4j\bin\service\WinRun4J.jar;D:\downloads\winrun4J-0.3.3\winrun4j\bin\service\WinRun4JTest.jar
[info] VM Args:
[info] vmarg.0=-Xdebug
[info] vmarg.1=-Xnoagent
[info] vmarg.2=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n
[info] vmarg.3=-Djava.class.path=D:\downloads\winrun4J-0.3.3\winrun4j\bin\service\WinRun4J.jar;D:\downloads\winrun4J-0.3.3\winrun4j\bin\service\WinRun4JTest.jar
[info] Program Args
[info] arg.0=hallo
[info] arg.1=hallo2
[info] arg.2=hallo3
[info] Main Class: org/boris/winrun4j/test/TestServiceArgs
Listening for transport dt_socket at address: 8787
[info] Registering natives for Log class
[info] Registering natives for INI class
[info] Registering natives for SplashScreen class
[info] Registering natives for Registry class
[info] Registering natives for Shell class
[info] Registering natives for EventLog class
[info] args.length=0
[info] TestServiceArgs running…
As you can see I pass 3 args but in the main method the args[].length is 0
3: Don’t set the working.directory=. causes the working.directory to be C:/WINDOWS/system32
Regards,
Rainer
poidasmith 8:44 pm on July 27, 2009 Permalink |
Hi,
For 1. Try adding the -Xrs vm option – this should prevent the shutdown on logoff.
For 2. How are you setting the start parameters? Is it via the service properties, general tab, start parameters?
For 3: This will be set by the service control manager – I guess it would be reasonable to default the working directory to “.” when running as a service. I’ll add this to the todo list.
Thanks,
Peter
MistaP 6:18 pm on November 25, 2009 Permalink
Using the WinRun4J64c.exe, I tried setting two args, I get the same issue as Rainer
MistaP 9:58 am on November 26, 2009 Permalink
I set the paramaters in Properties tab and hit start. That passed the parameters in, but the nt service will not save those parameters. I was hoping the ini file would work, as a workaround for now I test if the args passed in is lenght is 0, if so then build the args from a vmarg.X=-Darg.1=myValue
fyi on another note; I had service.class=foo and main.class=foo in the same ini file, that causes issues, I kept getting told ClassNotFound until I removed main.class
P
poidasmith 9:40 am on November 27, 2009 Permalink
Hi,
I’m not aware of a way to get windows to save those start parameters. You’re best bet is to add the properties you need to the ini file and then use the INI class to access these directly.
The main.class/service.class is the switch to tell the launcher which mode to use instead of having to specify mode=service as another parameter… it should probably output an error message if you specify both main.class and service.class.
Cheers,
Peter
doschhar 7:26 pm on September 11, 2009 Permalink |
Oh – mabye my first reply did not work – got a huge error msg …
Found a small glitch with the icon handling of the WinRun4J.exe – once added it only shows the small icon in the explorer – on the desktop still shows the “running guy” icon. With WinRun4Jc.exe booth icon work – strange?!
Nice tool,
Harald
Stas 9:53 am on October 21, 2009 Permalink |
Hi!
I’d like to help WinRun4J with Ant task.
Please contact me if you’re interested.
acarman 5:36 pm on November 4, 2009 Permalink |
Hi,
We are looking at using this software to inject some icons into executables. We however would like to have the ability to use it under linux to create windows executables.
I had a peek a the source code, and the portion of the program pertaining to what we would like to acomplish seems to use a winapi call UpdateResource. If this is so, it is possible that you know of a way this is doable under java?
Is a java port somthing that is even possible, this would be the best option for what we are looking at.
Thanks
poidasmith 8:53 pm on November 4, 2009 Permalink |
Hi,
It won’t be possible to port this easily – its the windows api call that is doing all the work. A java one is possible and is almost complete at: http://pecoff4j.sourceforge.net/ (one of my other projects). This is a parser/assembler for windows exe/dlls. It still needs a little more work on resource entries and assembling though.
Regards,
Peter
acarman 3:07 pm on November 5, 2009 Permalink
Peter thank you very much for your response. We will be following pecoff4j very closely. This seems to be exactly what we need!