New Version of WinRun4J (0.4.3) Available

Head over to the WinRun4J Sourceforge Page to download.

This includes the following fixes/improvements:

  • Fixed loading issue with Java 7
  • Added a standalone java service wrapper

Edit: Also note that the source code for WinRun4J has now moved to GitHub. Head over to the WinRun4J Github Page to view/download/fork.

Advertisements

44 Responses to New Version of WinRun4J (0.4.3) Available

  1. Chris says:

    Hi Peter,

    I ran into a problem using WinRun4J with connecting to Oracle UCP connection pool. I have a stripped down sample program I can send to you and the errors I am getting. Can you send me an email to clankest8-at-hotmail.com

    Chris

  2. Philippe says:

    Hello,

    I’m using winrun4J-0.4.3. I was able to install the demo and its running (it logs the Windows Events). But when I try with a custom jar, the service don’t want to start; I get that error “Error 1053: The service did not respond to the start or control request in a timely fashion.”. [I tried with a standard jar and with a runnable one.]

    Can someone send pinpoint my mistake?

    Thanks!

    Philippe

    File:
    ca.telecine.WinRun4jTutorial.v0.01.jar
    service.exe
    service.ini
    WinRun4J.jar

    INI:
    service.class=ca.telecine.WinRun4jTutorial.WinRun4jTutorial
    service.id=WinRun4jTutorial
    service.name=WinRun4jTutorial
    service.description=Test WinRun4jTutorial.

    classpath.1=*.jar

    vmarg.1=-Xdebug
    vmarg.2=-Xnoagent
    vmarg.3=-Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n

    Jar code:

    package ca.telecine.WinRun4jTutorial;

    import org.boris.winrun4j.EventLog;
    import org.boris.winrun4j.ServiceException;
    import org.boris.winrun4j.AbstractService;

    /** A basic service. */
    public class WinRun4jTutorial 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;
    }
    }

    • poidasmith says:

      Could you add a “log” INI setting to log the launcher messages to a file?

      Or set “log.output.debug.monitor=true” and then grab DebugView from http://technet.microsoft.com/en-us/sysinternals/bb896647

      Then report back with the information?

      Thanks,
      Peter

      • Philippe says:

        Hello Peter,

        I’m using the code from your tutorial at https://borisinc.wordpress.com/tag/winrun4j/ and I’m having a compilation error saying that “SERVICE_ACCEPT_STOP and SERVICE_ACCEPT_SHUTDOWN can not be resolve to a variable”. Do I need to create those variable? And with which values? [If you have a working exemple – source included – I’ll appreciate it.]

        Thanks!

        Philippe


        public int getControlsAccepted() {
        return SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
        }

      • poidasmith says:

        Hi Phillippe,

        The Service interface (org.boris.winrun4j.Service) defines the constants so if you implement this interface they will be in scope in your class.

        Regards,
        Peter

  3. Jana says:

    Hey,

    I want to use winrun4J to run a jar-file as service. this jar needs two paramerter. how can I pass this paramater by start the jar as a service.

    thx and best regards

    jana

    • poidasmith says:

      You can add application parameters to the INI file (arg.1, arg.2). These will be passed to the serviceMain method.

  4. Robert Egglestone says:

    Thanks for WinRun4J! – it’s the only actively maintained launcher I’ve been able to find that allows the app to be run in the same process.

    I had problems with the embedded classloader failing to load resources, for anyone else running into the same problem, a simple alternative is to concatenate the jar on the end of the exe, and add itself to the classpath.

    myapp.ini
    classpath.1=myapp.exe

    build.xml

    I read about this approach a few years back, it’s not exactly good, but apparently it works because zips are indexed from the end of the file whereas exes start from the beginning.

    Cheers,
    Robert

    • Robert Egglestone says:

      WordPress stripped out the XML tags for build.xml, they were…

      concat destfile=”myapp.exe” binary=”yes”
      fileset file=”winrun4j.exe”
      fileset file=”myapp.jar”

  5. Alexy says:

    Hello.
    There was a problem at attempt to launch .jar as service. At creation of object from a packet .javax arises nullPointerException:

    XPathFactory xpFactory = XPathFactory.newInstance ();

    And, as JAVA application all stablly works.
    I will be grateful for the answer.

    P.S. Excuse me for my bad English.

  6. Johannes Correa says:

    Hello and Thanks for WinRun4J. After a little work i was able to run a service by extending the AbstractService class and keep a log of the execution.

    But, I have two issues:
    1. When i try to stop the service, it never stops. I have to kill the process manually at the task panel. What do I have to do into my service class to handle properly the stop signal?
    2. I have certain business logic conditions that i have to check before the service logic start. I need to stop the execution and send a signal to windows that the service has not started properly. My first attempt was to throw a ServiceException but in Service Manager the service still appears to be initiated successfully. Should i have to return a value different from 0? Should i have to set the ‘shutdown’ variable to true?

    Thanks for your help.

    • poidasmith says:

      I have a few fixes queued related to starting/stopping services and will hopefully release a new version in the next couple of days.

      For point 2, you could try simply calling System.exit() with a non-zero exit code.

      • Johannes Correa says:

        Thanks for your answer.
        First, I will wait for the new version to try it, because my temporal solution was to apply a System.exit() at the end of the serviceMain method.
        For point 2, that is what i am doing right now but the problem would be that Windows would show an error message like “the communication with service has failed”, not that the service has not started successfully, which it would be the expected scenario.
        Finally, i have a question: what’s the difference between controls STOP and SHUTDOWN?

  7. jensen says:

    Is the WinRun4j plugin for Eclipse known to be functioning correctly? It appears that I have added it to Eclipse as a plugin, but Eclipse cites the WinRun4j version as 0.1.3 (as opposed to 0.4.3), and the Eclipse “Run As” list doesn’t include WinRun4j as an option. (Only the standard run as “java application” is present.) I’m using Eclipse version 3.3.2.

    • poidasmith says:

      The Eclipse plugin is versioned separately – 0.1.3 is the latest version. Actually, this is bundled with an older version of the launcher (on my todo list) – but this can be changed easily by replacing the files under:

      [ECLIPSE_DIR]\plugins\org.boris.winrun4j.eclipse_0.1.3\launcher

      I assume you mean eclipse 3.6.2? I haven’t tested on a really old version of eclipse for a while now.

      Also, do you see the preferences under Window – Preferences – Java – WinRun4J?

    • poidasmith says:

      Just checked the manifest – it requires at least 3.4.4. I’ll try to get a build out without this restriction (don’t think it really needs that version).

      EDIT: actually, double-checked and it does needs a few features from that version. Will update the site to reflect this.

  8. stephenG says:

    Three things:
    1) Great product. Easy to setup and use. Thanks for creating it
    2) We were getting the dreaded 1053 error with our service. It turns out that we had left the main.class in our ini file and once we removed that, things worked fine.
    3) Is there a way to get the plug-in to produce a service? Can I get the export tool to read an ini file in my project and embed it into the .exe? Right now we have to export the exe without the ini embedded and then manually copy our INI settings from a text file into the one produced by the plug-in. Naturally, these changes get overwritten every time we do the export.

    • poidasmith says:

      1. Thanks for the feedback.
      2. Seems like a fairly common gotcha with the launcher – I will add an extra check to warn if both main.class and service.class are present.
      3. Yes, I plan on adding support for generating a service via the eclipse plugin.Although for your case it might be better to create an Ant script that will generate your launcher?

  9. Tom S says:

    Please add a link to the javadocs (http://winrun4j.sourceforge.net/javadoc/org/boris/winrun4j/package-summary.html) to the SourceForge home page – they are there, but as-is you just have to know it (or do a Google search) to see them.

    • poidasmith says:

      Thanks – the link used to be there but must have got lost at some point. Will update the website.

  10. Sangaran says:

    Hi

    I have installed Winrun4j for eclipse. I updated the latest version of winrun4j by coping the latest version 0.4.4 into launcher folder of eclipse. I ran the program as winrun4j application inside eclipse it says failed to load JVM. I am using jre 7. Also when I export as winrun4j application it runs properly. but when i make it as service it starts normally but fails to stop giving 1053 error. Eclipse version 3.7.1

    I have wrote a test service class.
    ——————————————————————————-
    package com.backgroundservice;

    import org.boris.winrun4j.AbstractService;
    import org.boris.winrun4j.ServiceException;

    public class BackgroundService extends AbstractService {
    private volatile boolean shutdown = false;

    public int serviceMain(String[] args) throws ServiceException {
    BackGroundProcess bp= new BackGroundProcess();// not a thread
    bp.initializeLogger();// logger initialization
    while (!shutdown) {
    try {
    bp.run();
    Thread.sleep(60000);
    } catch (InterruptedException e) {
    e.printStackTrace();
    }
    }
    return 0;
    }
    }
    ———————————————————————————-
    My service.ini file content as follows.

    log=log.txt
    log.level=info
    log.overwrite=true
    service.class=com.backgroundservice.BackgroundService
    service.id=BPS
    service.name=BackgroundService
    service.description=Test Background Service.
    service.startup=auto
    classpath.1=*.jar

    please let me know what could be the issue. thanks in advance

    • poidasmith says:

      Are you able to show the output of log.txt for your service? We need to see what the actual error is. Thanks.

      • Sangaran says:

        [info] Module Name: C:\Users\skannan\Desktop\BEPM\service.exe
        [info] Module INI: C:\Users\skannan\Desktop\BEPM\service.ini
        [info] Module Dir: C:\Users\skannan\Desktop\BEPM\
        [info] INI Dir: C:\Users\skannan\Desktop\BEPM\
        [info] Registering Service…
        [info] Service startup mode: SERVICE_AUTO_START

        This is the content after make it as service. Please let me know if anything wrong.

        Thanks

  11. Morten Isaksen says:

    I have a small problem with version 0.4.4. I use it as a service wrapper. The service starts fine but when I stop the service I get error 109. The pipe has been ended.

    I think it is related to the System.exit(0) in MainService.java.

    This page describes the problem a bit: http://www.devx.com/Java/Article/34438/1954

    • poidasmith says:

      Yes, it does sound like the issue here. I will look into it. As a workaround you could extend the AbstractService class – this gives you more control over the shutdown behaviour of your service.

  12. Tom S says:

    I’d like to suggest a new feature. For rcedit, add a new parameter to add a resource which is the name of the INI file the launcher will look for. The default would be the same as now (.ini) – this would allow us to set a different name (i.e -Launcher.ini).

    My problem is that I already have settings files named .ini for my java application, so when I wrap these, the launcher will see this file (and all the settings there it doesn’t know about). I haven’t tested yet to see if this will cause the launcher grief, but I know the ‘extra’ launcher settings would be flagged as unrecognized by my app if present.

    • poidasmith says:

      Hi Tom,
      Actually, this should already be possible. What you can do is embed a launcher INI and use the ‘ini.file.location’ INI key to point to another INI file. Would this work for you?
      Thanks,
      Peter

  13. Philippe says:

    Hello,

    I’m working with SOAP Web Services. Code is working on runnable jar. If a wrap the code in WinRun4j, I get an error:
    “Caused by: javax.xml.ws.WebServiceException: Error creating JAXBContext for W3CEndpointReference.” That code is working fine on other projects.

    Do we have to do something special in WR4j to use SOAP?

    Is there some known issues with web services or SOAP?

    Thanks!

    Philippe

    • poidasmith says:

      Hi,
      Are you trying to embed the jar inside the launcher? If so, there is a known issue related to getResource in the classpath. The launcher cannot currently extract arbitrary resources from an embedded jar via the getResource method.
      Thanks,
      Peter

      • Philippe says:

        Hellop Peter,

        Actually, WinRun4j wrapper is instanciating a class that calls SOAP. SOAP is call from Test().test().


        public class WinRun4jSoapServiceWrapper extends AbstractService{

        private final static Logger log = Logger.getLogger(ca.telecine.WinRun4jSoapServiceWrapper.WinRun4jSoapServiceWrapper.class);

        public int serviceMain(String[] args) throws ServiceException{
        while (!shutdown) {
        log.info("Test");
        try{new Test().test();}
        catch (Exception e) {log.error(e);}
        }
        return 0;
        }
        }

        Thanks!

        Philippe

  14. I’m unable to get the test service to run on either my XP or Win 7 boxes here. Copied the files, ran the EXE with the RegisterService option, tried starting from the Windows Services control panel, just as indicated in documentation. Registering service works fine, but starting service gives the 1053 error. I enabled logging to a file (log=serviceLog.txt added to the sample INI), but I don’t get any error messages, just the info on registering/unregistering. Windows event log shows error “A timeout was reached (30000 milliseconds) while waiting for the WinRun4J Test Service service to connect.”

    I know that this is probably something really stupid! Thanks for any assistance.

  15. Scott Skinner says:

    Can you explain the service.startup option in more detail? Using service.startup=auto, I can get a Java app to start on reboot, but the service shuts down if the user logs out. How do you prevent the service from stopping when a user logs out?

    • Robert Egglestone says:

      Adding -Xrs to the Java options should prevent it stopping on logout.

      • Scott Skinner says:

        Yes that worked perfectly. Can you explain what some of the other service.startup options do? For example, boot versus system.

    • Robert Egglestone says:

      The service.startup options appear to map directly to the Windows options:
      http://technet.microsoft.com/en-us/library/cc739213(WS.10).aspx

      boot – A device driver that is loaded by the boot loader.
      system – A device driver that is started during kernel initialization.
      auto – A service that automatically starts each time the computer is restarted and runs even if no one logs on to the computer.
      demand – A service that must be manually started. This is the default value if start= is not specified.
      disabled – A service that cannot be started. To start a disabled service, change the start type to one of the other values.

  16. Frank Seidinger says:

    I’ve tried to use winrun4j as a service with a project that uses spring with annotations, the java persistence api (JPA) with hibernate as SPI provider of JPA and an embedded HSQLDB server instance. If using the command line variant my project starts up fine but wrapping as a service fails.

    I’ve tried to track down the issue and found out that spring is able to start up the HSQLDB server successfully but fails to create an EntityManagerFactory. I cannot say exactly why but this are my guesses:

    1. The JPA frameworks fails to instantiate the JPA provider (here hibernate) through the SPI mechanism.
    2. Hibernate JPA as well as the spring framework relies heavily on byte code enhancer like javasisst, cglib or asm.

    Can someone help or give advice with this situation?

  17. Rob Stone says:

    Hi All,

    I have coded a service very successfully using your tool. It’s fantastic.

    I have just one issue. When using the EventLog.reportEvent function I find my service crashes after a period of use. If I remove this line from my logging function and just log to file it works perfectly.

    The service log (the one specified in the executable’s INI file) just ends abruptly with the line “APPLICATION ABORTED” having otherwise reported nothing unusual.

    If I increase the logging level it stops more quickly, If I lower it, it will last longer, indicating that the issue appears after a certain (undefined) amount of logging has happened.

    The messages DO appear in the event log, so it is working as long as it is running.

    It strikes me that this is probably the result of a memory leak or memory access fault, or something else of that nature that occurs in the EventLog.reportEvent method.

    My question is simple… Are there any gotchas you are aware of relating to use of the EventLog method that may cause this behaviour. Is this something you have seen before?

    One idea I had was that perhaps the strings I’m passing are not encoded in a compatible character set for instance.

    For legacy reasons relating to what I am integrating with, I am using JRE 1.5(.22).

    Many thanks

    • Rob Stone says:

      One more thing. The message string appears in the binary data section of the event log, not the text description. I’d prefer it to appear in the text description. Looking at the source for the reportEvent method, my interpretation is that that’s just how it works and I would need to customise it to get the effect I’d like.

      Is that correct or is this already supported in some way other?

      Thanks again.

      Rob

      • Rob Stone says:

        Yet one more thing… sorry.

        I am seeing the issue in both Windows 2003 32 bit and Windows 2008 64 bit environments…

        and I’m using the latest version of WInrun4J (0.4.3).

        In case that helps.

      • poidasmith says:

        Thanks for the bug report Rob. I will do some testing and update this thread.

      • Rob Stone says:

        Thank you!

%d bloggers like this: