JNI  --  Windows Service (Java Service Wrapper)  --  Winamp

Hi!
I'm developing an application to control Winamp player and this application is supposed to run as a Windows Service (via Java Service Wrapper). Winamp is
handled via JNI (c library dll).
The thing is:
When I start the application as a service, my application tries to control Winamp (eg play, pause) but it doesn't work. I can see (prints) that my application is working but all the calls of the dll that interacts with Winamp don't answer. Instead, when I stop the service, I can see finaly all the prints (I introduced in the dll play, pause functions).
Can anybody give a hand? It seems that the JNI is not working properly (in my humble opinion).
Thanks for your attention.
Best Regards
Nuno

In my java application:
System.out.println("Before play!");
play( ); //Native method...
System.out.println("After play!");
sleep(10*1000);
System.out.println("Before pause!");
pause ( ); //Native method...
System.out.println("After pause!");
In c file (dll lib):
JNIEXPORT void JNICALL Java_WinampController_play
(JNIEnv *env, jobject obj) {
          printf("-> cpp - Play \n");
initWinampHandle();
if (hwnd_winamp != NULL) {
SendMessageA(hwnd_winamp, WM_COMMAND, WA_PLAY,
WA_NOTHING);
          printf("<- cpp - Play \n");
JNIEXPORT void JNICALL Java_WinampController_pause
(JNIEnv *env, jobject obj) {
          printf("-> cpp - Pause \n");
initWinampHandle();
if (hwnd_winamp != NULL) {
SendMessageA(hwnd_winamp, WM_COMMAND, WA_PAUSE,
WA_NOTHING);
          printf("<- cpp - Pause \n");
Result... (log file)
Before play!
After play!
Before pause!
After pause!
And only after I stop the service, the cpp printf appear... :(
-> cpp - Play
<- cpp - Play
-> cpp - Pause
<- cpp - Pause
Thanks

Similar Messages

  • Java Service Wrapper service is not being listed in the list of services

    I wrote a sample program which uses Java Service Wrapper. But it's not being listed as a Service in the list of Windows' Services. Any ideas why?
    Thanks.

    Hi Amar,
    need your help. i am facing the same issue.
    how did you resolved it . please let us know.
    Thanks,
    Santosh

  • Run Java App as a Windows Service

    Hi,
    Is there an easy way (without 3rd party software) to run a Java app as a service in windows?
    Sorry if this isn't the right forum to post to...
    Any help would be greatly appreciated!
    Thanks in advance!

    Nope there isn't. And there also isn't a reason not to use 3rd party software as there is an excellent open source API to do this job: Java Service Wrapper.

  • Running Java Applications as a Windows Service

    Hi,
    can any one help me to develop windows services in java.
    Running Java Applications as a Windows Service
    Any example or link please send me.
    Thanks and regards.
    Amit.

    See the Java Service Wrapper at
    http://wrapper.tanukisoftware.org/doc/english/introduction.html
    It's really good and easy to use.
    Bye.

  • Java Program as a Windows Service

    Hi,
    I was just wondering if it is at all possible to get a java program to run as a windows service? I have a program which updates a database which i could really do with simply running in the background. If anyone could help i would be most greatfull.
    Chirs
    P.S. If you can is it possible to schedule it to run at a certain time?

    There is a free wrapper tool called JavaService I dont remember from where I downloaded it. Just do a goole search for "JavaService"

  • Start and Stop a Windows Service From Java

    Is there any way to start and stop a Windows service from Java? The only post I found on it (http://forum.java.sun.com/thread.jspa?threadID=647509) had a link to one of the many aps that allow Java programs to be services, which is not what I am interested in doing.
    I am attempting to get data from performance counters from the Windows Performance Monitor into a Java ap without using JNI. I can get the data from C++ or a .net language pretty easily and was going to create a service that would listen for socket requests and feed back the data. However, I'd like to start and stop that service when my java code starts and stops. Is this possible? Would it make more sense to just use a .exe and Runtime.exec()?

    If it's only to start or stop a service then you could use the net command without any need for JNI.import java.io.*;
    public class MsWinSvc {
        static final String CMD_START = "cmd /c net start \"";
        static final String CMD_STOP = "cmd /c net stop \"";
        public static int startService(String serviceName) throws Exception {
            return execCmd(CMD_START + serviceName + "\"");
        public static int stopService(String serviceName) throws Exception {
            return execCmd(CMD_STOP + serviceName + "\"");
        static int execCmd(String cmdLine) throws Exception {
            Process process = Runtime.getRuntime().exec(cmdLine);
            StreamPumper outPumper = new StreamPumper(process.getInputStream(), System.out);
            StreamPumper errPumper = new StreamPumper(process.getErrorStream(), System.err);
            outPumper.start();
            errPumper.start();
            process.waitFor();
            outPumper.join();
            errPumper.join();
            return process.exitValue();
        static class StreamPumper extends Thread {       
            private InputStream is;
            private PrintStream os;
            public StreamPumper(InputStream is, PrintStream os) {
                this.is = is;
                this.os = os;
            public void run() {
                try {
                    BufferedReader br = new BufferedReader(new InputStreamReader(is));
                    String line;
                    while ((line = br.readLine()) != null)
                        os.println(line);
                catch (Exception e) {
                    e.printStackTrace();
    }Regards

  • Anyone familiar with the Java Service Wrapper?

    I'm getting errors when trying to use the Java Service Wrapper. My wrapper.conf file looks like this:
    # Wrapper License Properties (Ignored by Community Edition)
    # Include file problems can be debugged by removing the first '#'
    #  from the following line:
    ##include.debug
    #include ../conf/wrapper-license.conf
    #include ../conf/wrapper-license-%WRAPPER_HOST_NAME%.conf
    # Wrapper Java Properties
    # Java Application
    wrapper.java.command=%JAVA_HOME%\bin\java.exe
    # Tell the Wrapper to log the full generated Java command line.
    wrapper.java.command.loglevel=INFO
    # Java Main class.  This class must implement the WrapperListener interface
    #  or guarantee that the WrapperManager class is initialized.  Helper
    #  classes are provided to do this for you.  See the Integration section
    #  of the documentation for details.
    wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
    # Java Classpath (include wrapper.jar)  Add class path elements as
    #  needed starting from 1
    wrapper.java.classpath.1=C:\dbbackup\lib\wrapper.jar
    wrapper.java.classpath.2=%JAVA_HOME%\lib\tools.jar
    wrapper.java.classpath.3=C:\dbbackup\apps\JavaApplication110.jar
    # Java Library Path (location of Wrapper.DLL or libwrapper.so)
    wrapper.java.library.path.1=C:\dbbackup\lib
    # Java Bits.  On applicable platforms, tells the JVM to run in 32 or 64-bit mode.
    wrapper.java.additional.auto_bits=TRUE
    # Java Additional Parameters
    #wrapper.java.additional.1=
    # Initial Java Heap Size (in MB)
    #wrapper.java.initmemory=3
    # Maximum Java Heap Size (in MB)
    #wrapper.java.maxmemory=64
    # Application parameters.  Add parameters as needed starting from 1
    wrapper.app.parameter.1=JavaApplication110.Main
    # Wrapper Logging Properties
    # Enables Debug output from the Wrapper.
    # wrapper.debug=TRUE
    # Format of output for the console.  (See docs for formats)
    wrapper.console.format=PM
    # Log Level for console output.  (See docs for log levels)
    wrapper.console.loglevel=INFO
    # Log file to use for wrapper output logging.
    wrapper.logfile=../logs/wrapper.log
    # Format of output for the log file.  (See docs for formats)
    wrapper.logfile.format=LPTM
    # Log Level for log file output.  (See docs for log levels)
    wrapper.logfile.loglevel=INFO
    # Maximum size that the log file will be allowed to grow to before
    #  the log is rolled. Size is specified in bytes.  The default value
    #  of 0, disables log rolling.  May abbreviate with the 'k' (kb) or
    #  'm' (mb) suffix.  For example: 10m = 10 megabytes.
    wrapper.logfile.maxsize=0
    # Maximum number of rolled log files which will be allowed before old
    #  files are deleted.  The default value of 0 implies no limit.
    wrapper.logfile.maxfiles=0
    # Log Level for sys/event log output.  (See docs for log levels)
    wrapper.syslog.loglevel=NONE
    # Wrapper General Properties
    # Allow for the use of non-contiguous numbered properties
    wrapper.ignore_sequence_gaps=TRUE
    # Title to use when running as a console
    wrapper.console.title=Test Wrapper Sample Application
    # Wrapper Windows NT/2000/XP Service Properties
    # WARNING - Do not modify any of these properties when an application
    #  using this configuration file has been installed as a service.
    #  Please uninstall the service before modifying this section.  The
    #  service can then be reinstalled.
    # Name of the service
    wrapper.name=dbbackup
    # Display name of the service
    wrapper.displayname=dbbackup
    # Description of the service
    wrapper.description=Test Wrapper Sample Application Description
    # Service dependencies.  Add dependencies as needed starting from 1
    wrapper.ntservice.dependency.1=
    # Mode in which the service is installed.  AUTO_START, DELAY_START or DEMAND_START
    wrapper.ntservice.starttype=AUTO_START
    # Allow the service to interact with the desktop.
    wrapper.ntservice.interactive=false
    STATUS | wrapper  | 2010/04/05 19:56:22 |
    STATUS | wrapper  | 2010/04/05 19:56:22 | Launching a JVM...
    INFO   | wrapper  | 2010/04/05 19:56:22 | command: "C:\Program Files\Java\jdk1.5.0_11\bin\java.exe" -Djava.library.path="C:\dbbackup\lib" -classpath "C:\dbbackup\lib\wrapper.jar;C:\Program Files\Java\jdk1.5.0_11\lib\tools.jar;C:\dbbackup\apps\JavaApplication110.jar" -Dwrapper.key="uDobXEdkbmmNM22u" -Dwrapper.port=32000 -Dwrapper.jvm.port.min=31000 -Dwrapper.jvm.port.max=31999 -Dwrapper.pid=584 -Dwrapper.version="3.4.0" -Dwrapper.native_library="wrapper" -Dwrapper.cpu.timeout="10" -Dwrapper.jvmid=1 org.tanukisoftware.wrapper.WrapperSimpleApp
    INFO   | jvm 1    | 2010/04/05 19:56:23 | WrapperManager: Initializing...
    INFO   | jvm 1    | 2010/04/05 19:56:23 |
    INFO   | jvm 1    | 2010/04/05 19:56:23 | WrapperSimpleApp Usage:
    INFO   | jvm 1    | 2010/04/05 19:56:23 |   java org.tanukisoftware.wrapper.WrapperSimpleApp {app_class} [app_arguments]
    INFO   | jvm 1    | 2010/04/05 19:56:23 |
    INFO   | jvm 1    | 2010/04/05 19:56:23 | Where:
    INFO   | jvm 1    | 2010/04/05 19:56:23 |   app_class:      The fully qualified class name of the application to run.
    INFO   | jvm 1    | 2010/04/05 19:56:23 |   app_arguments:  The arguments that would normally be passed to the
    INFO   | jvm 1    | 2010/04/05 19:56:23 |                   application.
    ERROR  | wrapper  | 2010/04/05 19:56:24 | JVM exited while loading the application.
    STATUS | wrapper  | 2010/04/05 19:56:28 | CTRL-C trapped.  Shutting down.
    STATUS | wrapper  | 2010/04/05 19:56:28 | <-- Wrapper Stopped

    I got it to work. Still not sure what I was doing wrong. I just copied a wrapper config I had for launching JBoss and implemented it into my application.
    wrapper.java.command=%JAVA_HOME%/bin/java
    wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
    wrapper.java.classpath.1=C:/dbbackup/lib/wrapper.jar
    wrapper.java.classpath.2=%JAVA_HOME%/lib/tools.jar
    wrapper.java.classpath.3=C:/dbbackup/bin/JavaApplication110.jar
    wrapper.java.library.path.1=C:/dbbackup/lib
    # these are the JAVA_OPTS
    wrapper.java.additional.1=-Dprogram.name=%PROGNAME%
    wrapper.java.additional.2=-server
    wrapper.java.additional.3=-Xms128m
    wrapper.java.additional.4=-Xmx512m
    wrapper.java.additional.5=-Dsun.rmi.dgc.client.gcInterval=3600000
    wrapper.java.additional.6=-Dsun.rmi.dgc.server.gcInterval=3600000
    wrapper.app.parameter.1=javaapplication110.Main
    wrapper.logfile=C:/dbbackup/logs/wrapper.log
    wrapper.ntservice.name=DBbackup
    wrapper.ntservice.displayname=DBbackup
    wrapper.ntservice.description=Starts and stops
    wrapper.ntservice.starttype=AUTO_START

  • Windows services vs java

    Hi,
    I just want to get the status of windows services( SERVICE_NAME: DWMRCS)
    and also i have to stop and start the services through java code is there any help?
    thanks

    There are frameworks that make this relatively easy (google "Java Service" and you'll find them). Alternatively, you can write the service DLL yourself and instantiate your Java objects using JNI.
    If you are already familar with creating NT services, then JNI would be the way to go.
    Given the requirements of your project, it sounds like you will have to go the JNI route - and learn quite a bit about how to hook into the Windows login dialogs...
    - K

  • How to execute a java pgm thru Window service

    How can we execute a java pgm thru window service, now am executing thru a .bat file but want to change it as window service

    http://sourceforge.net/projects/wrapper/

  • Rmid and Java Service Wrapper

    I attempted to run RMID by specifying the 'main' class to Java Service Wrapper but ran into trouble with permissions. Even a security policy granting all permissions wasn't sufficient.
    Has anyone succeeding in running RMID this way? Or any other way of running it properly as a Windows service (SRVANY doesn't count as it doesn't shutdown RMID cleanly).
    When asked to shutdown the service, SRVANY abruptly terminates RMID. This means that any 'child' JVM's remain rather than being shutdown. In addition, on Vista, it often results in an IPv6 port 1098 persisting and blocking a subsequent attempt to restart the service.

    mthornton wrote:
    The problem was Java permissions not operating system permissions. I tested it under my own account.
    Have you succeeded in getting rmid running under Java Service Wrapper?I have many apps in production using the Java Service Wrapper but none with rmid, sorry.
    You said that you have adjusted the Java permissions.
    Did you follow the advice in the FAQ ?
    http://wrapper.tanukisoftware.org/doc/english/faq.html#5

  • Install of WAS 6.40 java on windows no windows services created

    We are trying to install a NW04 SR1 WAS on windows. The latest Install Master CD download now requires Oracle 10. The Oracle 10 install is the first part of the install process. The Note number 949116  says to use the procedure for the Oracle install in the NW 2004s SR1 install guide.
    We have followed these instructions and after running the Oracle installer via sapserver.cmd we get a successful completion with 0 byte error file.
    We are installing over Remote Desktop as a user who is a member of the local Admin group.
    But the only windows service created is iSQL.
    I tried using both mstsc & mstsc /console but the services are still not created.
    Has anyone had the same problem?
    Regards
    Chris

    Thanks for your help Gopal
    The documentation is very bad on this process so for anyone who is following the the upgrade of R/3 internet sales from J2EE Engine 6.20.
    Use the following;
    6.20/6.40 based products Installation Master (Edition Sept. 2006) Number 51032143
    Download IGS, SCS, Crypto Lib & SAP:J2EE-CD:640SR1:J2EE-CD::
    Download Oracle 10, 5 files rebuild cd by clicking on the.exe file
    Install Oracle 10 (Don't expect to see an operational RDBMS i.e no services)
    Install NW04s SR1 java via Install Master SAPInst
    Install CRM Component ISA R/3 via Install Master SAPInst
    Hope this helps
    Regards
    Chris

  • Run windows services from java application

    can java application run a windows server
    i have a web server that runing using tomcat and mysql
    can i make a icon in the systray
    that give me the option to (using a menu)
    run the server ,wicth means : tomcat and mysql are runing
    stop the server
    get tomcat stacktrace in a window
    i was thinking about runing tomcat and mysql as services
    and write the systray application using java,
    the systray application should acces window services ,
    and run/stop requierd services.
    what happend on a machine thar runs linux?
    thanks
    shay

    Ok .so it's will be a diffrent way under linux..
    for systray i will use http://systray.sourceforge.net/
    and for services i'll use the
    "net start <Service>" and "net stop service"
    i need to keep track on the service status
    so my Systray status will be updated
    what is the command for getting the status of the proccess
    thanks shay

  • Adding Java program as a Windows service

    Hi all,
    How can I run a Java program as a Windows service?

    There are free tools available...just google it.
    Try http://jslwin.sourceforge.net/

  • Getting windows services through java

    Hi,
    I just want to get the status of windows services( SERVICE_NAME: DWMRCS)
    and also i have to stop and start the services through java code is there any help?
    thanks

    Use "sc" util with Runtime.exec().

  • Java Service Wrapper

    Dear all,
    How could I turn the following java application into a service running under Linux and make it started automatically when the system is restarted using Java Service Wrapper?
    The instructions on the Java Service Wrapper website is too complex for me to follow. The application below just write the current time to a file every 5 seconds.
    If possible, please give me some step by step instruction about how to configure, install and verify the results.
    Thanks
    Yu
    package timertest;
    import java.util.Timer;
    public class Main {
        Timer timer;  
        public Main(int seconds) {
            timer = new Timer();
            //timer.schedule(new ReminderTask(),seconds * 1000, seconds * 1000);
            ReminderTask task = new ReminderTask();
            timer.scheduleAtFixedRate(task,seconds * 1000, seconds * 1000);
        public static void main(String[] args) {
            System.out.println("About to schedule task.");
            new Main(5);       
            System.out.println("Task scheduled.");
    package timertest;
    import java.util.TimerTask;
    import java.util.Date;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.lang.Thread;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.io.*;
    public class ReminderTask extends TimerTask {
        public synchronized void run() {
            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
            try {
                // Create file
                FileWriter fstream = new FileWriter("out.txt");
                BufferedWriter out = new BufferedWriter(fstream);
                out.write(dateFormat.format(new Date()));
                //Close the output stream
                out.close();
            } catch (Exception e) {//Catch exception if any
                System.err.println("Error: " + e.getMessage());
    }

    I suggest you read how to create a startup script in Linux. It doesn't matter that you program is written in java.
    [http://www.google.co.uk/search?q=linux+startup+scripts]

Maybe you are looking for

  • Installing Reader 10.1 to a drive OTHER THAN 'C' drive

    Hi. Can anyone provide guidance on how to install Adobe Reader 10.1 to a hard drive other than the C drive? At no point during the installation process is the user given the option to select a drive letter. I need space on my C drive and want to inst

  • 1st gen ipod touch. updated apps dont work.

    i recently updated my applications and games on my ipod touch first generation. i was aware the update was for 4.0 ipod touchs but it had other in game updates as well. but when i tried to open the app it stayed open for about 3 seconds had the logo

  • Problem with Windows Vista, PC Suite and E90

    PC Config: SO: Microsoft Windows Vista Business TabletPC (ENG Language)(with all the Updates for the SO). Nokia: PC Suite 6.84.10.3 Phone: Nokia E90 Comunicator with firmware V07.24.0.3 -12/06/07 - Nokia E90-42 After installing the PC Suite and estab

  • Cost Center Substitution - KB21N

    Hello, I am trying to use a Cost Center substitution on transaction KB21N to bring in the employees HR Mini Master Cost center when manually charging labor through KB21N. The problem is that the susbstitution populates both Sending and Receiving Cost

  • Question about iTunes syncing

    Hi, how do I sync only 1 movie from my itunes, onto a friends ipod? i need to know how to do this so when i press sync all my music and other movies dont go on my friends ipod, just the video i want.