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.

Advertisements

44 Responses to WinRun4J 0.3.3 Released

  1. nielm says:

    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 says:

      Yes, this is a good point. I’ll update the documentation to point this out for the moment.

      • Kirill says:

        I proud that I also took a part in winrun4j logging! (log & log.overwrite options 🙂

  2. jaking says:

    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 says:

      Hi,

      Problem solved by replacing jre/bin witj jre/bin/client/jvm.dll

      • poidasmith says:

        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 says:

        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 says:

        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 says:

        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

  3. jaking says:

    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 says:

      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 says:

        Hi,

        Yip, I was using WinRun4Jc.exe – changed it for WinRun4J.exe and no command window appears.

        Thank you

  4. weishaupt@bernot.net says:

    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 says:

      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 says:

        Using the WinRun4J64c.exe, I tried setting two args, I get the same issue as Rainer

      • MistaP says:

        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 says:

        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

  5. doschhar says:

    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

  6. Stas says:

    Hi!
    I’d like to help WinRun4J with Ant task.
    Please contact me if you’re interested.

  7. acarman says:

    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 says:

      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 says:

        Peter thank you very much for your response. We will be following pecoff4j very closely. This seems to be exactly what we need!

      • Alex says:

        Peter,

        Have you made any progress on pecoff4j? We are very interested in no longer being windows dependent to build our launchers.

        Alex

  8. Steve says:

    Hi,

    I use following command to launch my application. I have a executable jar file rather than a main class. How to specify this in the ini file?

    “java -Djava.rmi.server.codebase=”file:MyApp.jar” -Djava.rmi.server.hostname=127.0.0.1 -Djava.security.policy=java.policy -jar MyApp.jar 400 1000 ”

    Thanks
    Steve

  9. Christoph says:

    Hi,

    I tried to build a service with included jar files.
    So I took you example and used:
    RCEDIT.exe /N service.exe service.ini
    RCEDIT.exe /J service.exe WinRun4J.jar
    RCEDIT.exe /J service.exe WinRun4JTest.jar

    RCEDIT.exe /L service.exe showed me, that all files have been included, but after registering and starting the service I received an error. Could it be, that the classpath isn’t set correctly on putting in the jar files, or can’t I use the WinRun4Jc.exe with included jars??

    Thanks
    Christoph

  10. Mastica says:

    Hi!.. I tryed WinRun4J but when I lunch the service example form the control panel services console, after have it registered, I receive the error message 1053.. any suggest?

  11. arreumb says:

    I got the same: Error 1053, the service did not respond to the start or control request in a timely fashion. Any idea on what could be the reason of this error ? The application runs fine when launched from the command line, but the service fails to start.

  12. Chris Dail says:

    Some others have mentioned this already, but the service argument still do not appear to be working in this release. It properly logs a message indicating it found the arguments are being passed in but args[] is empty on the Java side after the call.

    Config snippet:
    arg.0=-r

    Log snippet:

    [info] Program Args
    [info] arg.0=-r

    From my code logging out args.length gives a value of 0.

    • poidasmith says:

      Hi,

      Yes, you are right – the problem is that the service code doesn’t concatenate the args passed in from config with the ones passed in from the service control manager. I will get a fix out shortly. Thanks for the feedback.

      Cheers,
      Peter

      • Keshav says:

        Hi there,
        I am getting 1053 error as well. It works fine when i start it from command line but as a service it does not start. Does latest release have the fix or you working on it ?

        thanks a ton in advance

    • poidasmith says:

      Hi Chris, thanks for your feedback. This should be fixed in the new version.

  13. poidasmith says:

    @Keshav: I suspect your error isn’t related to the fix mentioned above. Its more likely that an error is occurring on the startup of your service.

    • Keshav says:

      thanks for the reply. When i start the program from command line using winrun4j, it starts fine. Only when installed as a service it throws 1053 error

  14. Mohsen says:

    Thanks for this great tool. I previously used launch4j in a product, but now I’m switching to WR4J, as we have some problems with L4J in 64-bit architectures and it seems to be now dead.

    I would like to ask a feature request: Support version info (as supported by Launch4J). Resource info entries like fileVersion, copyright, companyName, fileDescription, etc.

  15. Jeremy says:

    I found a bug. When configured as a windows service if your Service#main(String[]) method returns really fast, the service will still be reported as started.

    I think you should change the code in Service.cpp:373 (Service::Main) to call SetServiceStatus before CreateThread, then if the java method returns fast, the service will be set to stopped after being set to started. My problem was the background thread was setting the service to stopped before the main thread set it to started, and it was being marked as started.

    Also it would be nice if there was a way to control the service status, so that you could wait until your service was really ready before marking the service as started.

    • poidasmith says:

      Hi Jeremy,

      Thanks for the bug report, will incorporate a fix for the next release. I also agree it would be useful for the service to be able to report its own status so I’ll also add that to the next release.

      Cheers,
      Peter

      • Sudhir says:

        Peter,
        Will you be incorportaing this fix soon, since i guess the issue i am facing with regards to Error 1053?

    • poidasmith says:

      Thanks Jeremy, this is fixed in the new version.

  16. Krishna says:

    I want to implement “Service Example” given at http://winrun4j.sourceforge.net/ but it gives “Error 1053: The service did not respond to the start or control request in a timely fashion” when try starting the service.
    No one has addressed to this problem in previous posts even. Do need to change the code (ServiceTest.java) as well?

    • Paul says:

      Tried the service example – got “Error 1053: The service did not respond to the start or control request in a timely fashion” .

      Copied WinRun4J.jar to the test directory – seems to work as described!

    • Sudhir says:

      Hi,
      I am using WinRun4J to launch an ant build with opens a port, the application launches perfectly when launched from a command prompt. but it fails when launched as a service. i get the 1053 error.
      please let me know what the fix is?

  17. Jana says:

    Hey Boris,

    I want to use winrun4J to start/stop a jar.-file with a windowsservice. The JAR needs two parameters. How can I pass these on the service?

    Best Regards.
    Jana

  18. Hassan Ali says:

    Hi! I am using WinRun4J to make my java app run as a service. Everything goes right but when i attempt to stop my service from the Windows Services Panel the progress bar slows down and at the end prompts me with error: “Could not stop the MyAppService service on local computer
    Error 1053: The service didnot respond to the start or control request in a timely fashion”.
    I would be thankful i someone could give a hint or identify what exactly is going wrong. The code implementation is right to best of my knowledge. thanks
    regards,
    Hassan Ali.

%d bloggers like this: