Running single instace of the java application

Hi,
I developed a swing based application in java. I am running it through the executable jar. Each time clicking on the jar file it opens the new instance of the appliction.
But I want to open the single instance of the application i.e. If the application is running , then user tries to open another instance it should be display the error or running application only like yahoomessenger,notepad,etc.
Please tell me how it is done in java. send aly sample code or resources regarding this.
Thanks
in advance

use jni and access java PID... etc etc it is long way to do that... i think easiest way locking a file and whenever jar runs has to check file whether it is locked or not... if the file is locked, application quits.

Similar Messages

  • Any idea how the java application can get the physical memory?

    Hello, everyone
    Any idea how the java application can get the physical memory?
    thanks in advance

    I believe what yo intend to do is forbidden, but here
    my answer.
    when you start your application you can give your VM
    the entire memory of your pc. like this this memory
    is completly under your control.* headdesk *

  • To run the java application without jdk package

    i would like to know whether possible to make the java .class file as .exe file to run in window environment without the help of jdk package.....if the answer is yes,,,,,is it going to use the jvm???is it come together with window os or not and start from which windows version?? or do we need to use the jre??? actually i would like to make installation package to install an application in windowsxp....i know how to do that one in vb and i've done that one before using visual studio 6.0.....is there any possible way....but please explain in easy words and way coz i might not understand if too technical...nobody can help me in my college,,,even lecturers.....thanks a lot

    i would like to know whether possible to make the java .class file as >>.exe file to run in window environment without the help of jdk >>package.....Yes it is possible, there are many tools like one mentioned above to convert your java .class program to .exe and you dont need jdk for that, though you will need JVM
    if the answer is yes,,,,,is it going to use the jvm???Yes it needs a JVM
    is it come together with window os or not and start from which windows >>version?? You need some tool like PJ2Exe or one mentioned above to convert it to .exe, it wont be available with OS.
    or do we need to use the jre???Yes you will need to install JRE for the JVM
    actually i would like to make installation package to install an >>application in windowsxp....i know how to do that one in vb and i've >>done that one before using visual studio 6.0.....is there any possible >>way....Yes it is possible,
    Make a .exe of your application and using VB make a setup file which takes care of installing JRE as well as your application.
    Regards
    Rohan

  • Running ssh command in a java application

    Hi there!
    I am trying to run a ssh command from a java application cause I need to store the result.
    Actually I can run this command in the cygwin shell so I need to open the shell and run the command, all trough java.
    so, what my process needs to do is:
    1) open the cmd
    2) run C:\cygwin\cygwin.bat
    3) execute the ssh command
    ssh -l fip-user ipdb fip 42704) print the result of the ssh command.
    Note that the cygwin opens in the same command line window and so will print it's result to the same process inputstream
    Message was edited by:
    RBervini

    Use "Runtime.getRuntime().exec()" to execute the SSH program,
    and you can then get the output of the SSH program
    via the getInputStream() method on the returned Process object.
    Note: there are many pitfalls with this. In particular, most people don't know
    they should create separate threads to drain the input/output pipes.
    See this excellent classic article http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    on how to do it right.

  • Would the java applications be affected if change verison of Java 2 SDK

    This would be a very urgent information for me. Thanks a lot if you could help!!! :
    If the source codes I want to reuse is previously developed and tested with Java 2 SDK, Standard Edition (1.2.1_04) Production Release for Solaris, could I directly reuse them with Java 2 SDK, Standard Edition 1.3.1 for Windows? If not, what could I do to make the old Java application with Solaris to be able to run with Windows?

    If you application is pure Java (e.g. not running external programs or using JNI), then it should run w/o changes regardless of the platform. Of course, platform specific bugs may affect reality.

  • Sorry if i sound foolish how to run an applet through a java application

    I am into java from last one month ank keep on exploring it in the want to
    recently i created a application cum applet in the same class like
    applet is doing its own task and there is a main method in the code
    that does entirly different task lets assume displaying *'s on the dos prompt the program is getting complied and belive it its running as desired
    but the only problem that i m facing if i use appletviewer Myclass.java
    only the appletprog is displayed
    and if i run java Myclass than only dos task is done
    may be it is sounding foolish for most of you but if i can get a way
    which will help me in excecuting only one of it and both of them run succesfully
    it tryied different ways to do it but was not succesful
    please do not get irreated if its bizzered but if you really have a solution for it .i will appreciate it
    thanking you

    Yes you can run an Applet from an application. The magic bit is providing an AppletContext and AppletStub!
    Here's how you start it:
            wpa = new WayPointsApplet(this);
            new AppletWrapper(wpa, 380, 320);Here's the class definition: (includes code for my application that can be ignored.
    // Define a wrapper class for the applet
    class AppletWrapper extends Frame implements AppletStub, AppletContext {
        Applet applet;
        // Constructor
        AppletWrapper(Applet a, int x, int y) { 
              applet = a; 
              setTitle(a.getClass().getName());
              setSize(x, y);
              Dimension ss = Toolkit.getDefaultToolkit().getScreenSize();
              setLocation((ss.width-x)/2, (ss.height-y)/2);
              add(a, "Center");
              a.setStub(this);
              // Trap window closing
              addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent we) {
                    // Test if Write left undone before exiting???
                    if(WayPoints.wpa != null) {
                      if(!WayPoints.wpa.okToExit())
                         return;           // Ignore
                    applet.stop();
                    applet.destroy();
                    if(WayPoints.debug || WayPointDefs.plot_debug) {
                      SaveStdOutput.stop();
                    System.exit(0);         // EXIT Program
              });  // end WindowListener
              a.init();
              show();
              a.start();
       } // end constructor
        // AppletStub methods
        public boolean   isActive() { return true; }
        public URL       getDocumentBase() { return null; }
        public URL       getCodeBase() {
            return WayPoints.currDir;
        public String    getParameter(String name) {
            if (name.equalsIgnoreCase("DEBUG")) {
                if (WayPoints.debug)
                    return "YES";
                else
                    return "NO";
            if(name.equals("PLOTDEBUG"))
                return (WayPointDefs.plot_debug ? "YES" : "NO");
            if (name.equalsIgnoreCase("SERVER"))
                return "NO";
            return "";
        public AppletContext getAppletContext() { return this; }
        public void      appletResize(int width, int height) {}
        // AppletContext methods
        public AudioClip getAudioClip(URL url) { return null; }
        public Image     getImage(URL url) { return null; }
        public Applet    getApplet(String name) { return null; }
        public Enumeration getApplets() { return null; }
        public void      showDocument(URL url) {}
        public void      showDocument(URL url, String target) {}
        public void      showStatus(String status) {}
    } // end class AppletWrapper

  • Formate of an exe generated by the java application

    I want to read an .exe file generated by a java application through C++ but i don't know the formate of that file. when i open the file in text editor i can't see anything but the symbols.
    Can anyone out there tell me what will be the file formate of .exe generated by java application or any other way out

    Let me tell u some functionality of this application as i only have the jar file of this project.
    It is a graphical application just like MS Paint but it only draw text with different colors, change background color etc.
    i also generate some code of this project through a tool which convert .jar file to java code.
    As i don't know much about java so i can't able to understand completely this code.
    I am copying the code of action lister of open file menu....
    if (e.getSource() == openMenuItem) {
              ExampleFileFilter ssfFilter
              = new ExampleFileFilter("ssf", "Sedao Scene Format");
              chooser.setFileFilter(ssfFilter);
              if (System.getProperty("PROPERTY_APPLICATION_KEY")
              == "qc2.jar") {
              if (getApplicationMode() == 0) {
                   if (System.getProperty("PROPERTY_LAST_SCENE_DIR")
                   != null)
                   chooser.setCurrentDirectory
                        (new File(System.getProperty
                             ("PROPERTY_LAST_SCENE_DIR")));
                   if (chooser.showOpenDialog(this) == 0)
                   open(chooser.getSelectedFile(), false);
              } else if (!((SchedulePanel) schedulePanel).openSchedule())
                   JOptionPane.showMessageDialog
                   (this,
                   "There was an error loading the schedule file. please check it is a valid schedule file.",
                   "Error Loding Schedule", 0);
              } else if (System.getProperty("PROPERTY_APPLICATION_KEY")
                   == "Overlay.jar") {
              if (getApplicationMode() == 0) {
                   int returnVal = chooser.showOpenDialog(this);
                   if (returnVal == 0)
                   open(chooser.getSelectedFile(), false);
              } else if (getApplicationMode() == 1) {
                   boolean result
                   = ((SmartScheduleDesigner) schedulePanel)
                        .openSchedule();
                   if (!result)
                   JOptionPane.showMessageDialog
                        (this,
                        "There was an error loading the schedule file. please check it is a valid schedule file.",
                        "Error Loding Schedule", 0);
              chooser.removeChoosableFileFilter(ssfFilter);
         }

  • How to run a jar file using Java application.

    Hi all,
    I know that jar file can run using the following command, using the command prompt.
    java -jar jar-fileBut I don't know how to run that command through a Java code. Hope it's clear to you.
    So can you please explain how can I do it.
    Thanks,
    itsjava

    rayon.m wrote:
    The solution given by ropp appears to have nothing to do with what you asked about.Ok sir, I got the point.
    I've try a test as follows. But it doesn't give any output. Even not an exception.
            try {
                String[] temp = new String[]{"java", " -jar", " MainApp.jar"};
                Runtime rt = Runtime.getRuntime();
                Process proc = rt.exec(temp);
                int exitVal = proc.waitFor();
                System.out.println("ExitValue: " + exitVal);
                System.out.println("Temp_Values");
            catch(InterruptedException ex) {
                System.out.println(ex.getMessage());
            catch (IOException ex) {
                System.out.println(ex.getMessage());
            }I've debug and see, but the exitValue is even not exist at run time. Can you tell me where I'm going wrong.

  • Trouble running sample code from the java trails

    I'm trying to run Sun's DocumentEventDemo available on the trails. I can get it to compile successfully but I get several errors when I try to run it. After compiling the source, this is what I get when I try to run it:
    C:\listen>java -cp . DocumentEventDemo
    Exception in thread "main" java.lang.NoClassDefFoundError: DocumentEventDemo (wr
    ong name: events/DocumentEventDemo)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    The source is available from the java trails using the name DocumentEventDemo
    Thanks
    ~Sklave

    actually that is really helpful. My directories are most likely incorrect, but I'm coming to java from a c/c++ background and don't know how to make the directories correctly for the given package. I'll look that up and see what I get. In the meantime, if you or anyone else could follow up with a link or a quick explanation on packages and directories that'd be great too.
    ~Sklave

  • Regarding executing the java application

    Exception in thread "main" java.lang.UnsupportedClassVersionError: Hello (Unsupp
    orted major.minor version 49.0)
    at java.lang.ClassLoader.defineClass0(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)

    49.0 is the java.class.version of Java 5.0 -- meaning you code was compiled by a version 5.0 compiler (or later). The fact that you can't run it shows you are trying to use an earlier version of the JRE. Try this:
    java -versionThe solution is to make sure your javac.exe and java.exe match.

  • How to access the mapping of Groups and Roles in the JAVA Application

    We have mapped the EJB roles with the groups through the Visual Administrator. We have developed the SSO. We have developed the application through which we are creating the user and role and mapping that role with the created user. The created role is saved in some LDAP directory. The second application in which ejb methods are mapped with some security roles.The LDAP roles we are getting in Netweaver as groups and we can perform the mapping of the deployed ejb roles with the group.Now for the logged in user we want to get the roles mapped with it so that we can give/deny the access to the methods from EJB as per the role of that user .How we will get the access to the mappings of the roles with the group in the application, if I know the LDAP roles mapped with the user (since these roles are accessible as groups in the NetWeaver)
    For e.g.  From application created the user with the role as "manager". This role is stored in iPlanet directory.
    This directory is mapped in the Netweaver.The manager role is displayed as the group in the Netweaver.
    Created the EJB application with the method "displayTheAccountDetails() with the role as "ManagerRole"
    This role is mapped with the manager group. Now we are having the details about the logged in user and the LDAP roles mapped to it (maneger role). How I will get the access to the details that for this group which ejb role is mapped in the application. So depending on that I can allow/deny the access to the ""displayTheAccountDetails()" method to the logged in user.

    Do you, guys, work together?
    See the last answer in this thread: How database works in UCM?

  • Signing the java application

    Hi,
    I have written an application in java6 and created a exe wrapper using jsmooth. Every thing is working fine. When I run my application, I gets prompted for "authorized exe". So I need to signing my exe.
    My question is How can I do code signing for my application
    a). Either I sign the jar and then creating exe
    b). Or I need to sign the exe
    Thanks

    JL.Nayak wrote:
    Hi,
    I have written an application in java6 and created a exe wrapper using jsmooth. Every thing is working fine. When I run my application, I gets prompted for "authorized exe". So I need to signing my exe.
    My question is How can I do code signing for my application
    a). Either I sign the jar and then creating exe
    b). Or I need to sign the exeThat depends on what you want to achieve. If some Java mechanism tells you that you need to run signed code, then you probably need to sign the jar files, if Windows or some other software doesn't allow you to run unsigned code, then you probably need to sign the exe file.
    Anyway we'll need a lot more information (and especially more accurate information) to be able to help you 'I gets prompted for "authorized exe"' is not useful information post the exact message you get and what exactly you did before that message popped up.

  • How to "Refresh" the Java application

    I have made a time stamp that will display the current time. The following code are in the MyFrame Class. But I want to refresh the time stamp so that it can continuously display the current time every second. How can I do this? Thank you.
    void jTime_actionPerformed(ActionEvent e) {
            date.time();
            date.setTimeStamp(jTimeLabel);These are the methods in the ClsDate Class.
    public void time()
        GregorianCalendar calendar = new GregorianCalendar();
        Hour = +calendar.get(calendar.HOUR);
        Minute = +calendar.get(calendar.MINUTE);
        Second = +calendar.get(calendar.SECOND);
      public void setTimeStamp(JLabel T4)
        T4.setText(toString());
      public String toString()
        return (Hour + ":" + Minute + ":" + Second);
      }

    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import java.util.Date;
    import javax.swing.*;
    public class TimerExample implements Runnable {
        private JLabel timeLabel;
        private ActionListener al = new ActionListener() {
            DateFormat df = new SimpleDateFormat("HH:mm:ss");
            public void actionPerformed(ActionEvent evt) {
                timeLabel.setText(df.format(new Date()));
        @Override public void run() {
            timeLabel = new JLabel("__:__:__");
            new Timer(1000, al).start();
            JFrame f = new JFrame();
            f.getContentPane().add(timeLabel);
            f.pack();
            f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        public static void main(String[] args) {
            EventQueue.invokeLater(new TimerExample());
    }

  • Running a db2 command from Java Application ??

    Hi All,
    I have to write an application in JDBC that can retrieve a list of databases on a db2 server, the only way I know is the db2 command "list database directory", but I can not use it in a JAVA program, is there a solution for this?
    Can anyone help me in this regard ?
    Thanks in Advance.

    If your driver implement it you can list databases with DatabaseMetaData
    Connection conn = ...
    DatabaseMetaData meta = conn.getMetaData();
    ResultSet rs = meta.getCatalogs();
    while (rs.next())
        System.out.println(rs.getString("TABLE_CAT"));
    }

  • Executing jar command from the java application

    Hi All,
    In my application i want to create a jar file with the existing class @ Runtime and want to download . But i tried to execute the jar command via Process.getRuntime, it throws IOException. Please guide me or give the solution

    PavithraKarthikeyan wrote:
    Please guide me or give the solutionQuestion your need for this. Why do you think you need to create the jar file.
    P.S. The jar command is only available if the user has the JDK installed so if he has only the JRE installed then you have a problem using Runtime.exec(). There are classes (java.util.jar.JarFile et al) that will allow you to jar files using Java code.

Maybe you are looking for

  • IPOD Not being Recognised

    After updating my Itunes software, my Ipod is now not recognised by ITunes! I have been through all the suggestions, but to no avail!!! On top of this I have lost all of my recordings on the Ipod, the only ones left are on the Itunes software on the

  • How to change the name of an existing user?

    i found this command on this other website but i have been hesitant to try it because im araid it might screw everything up usermod -l login-name old-name http://www.cyberciti.biz/faq/howto-chan - r-name-id/ now my understanding is that i would also

  • Inner interface bug ???

    Have I just discovered a bug in java ? The following actually give error stating: qualified new of static class By right, it should be compile and working but it is not ... can someone give comment ?? thank public class InnerInterfaceTest      interf

  • Installing repository

    Designer 6i r4.11 on Windows 2000 Svr and Pro (Client) - Database 8.1.7 I have one repository working good. I created a second database and tray to install another repository but I receive the message: CDR-21244: This process has been aborted

  • Is it better to synchronize first, then Multicam?

    A short film I am editing was shot on two cameras and one external audio track. I understand there are several ways to get these clips together. Depending on which way chosen, it will have a different arrangement in the inspector. With that in mind,