Double-clicking Java class file on Windows

Discussion in 'Java' started by hiwa, Jun 3, 2006.

  1. hiwa

    hiwa Guest

    I know this really is a Windows issue but
    I can't find its official documentation nowhere.

    My question is: how to enable double-click
    launching of a Java class which has main()
    method, via Windows filetype association
    mechanism?

    If we can't do it, then, why it is?
    hiwa, Jun 3, 2006
    #1
    1. Advertising

  2. hiwa wrote:
    > I know this really is a Windows issue but
    > I can't find its official documentation nowhere.
    >
    > My question is: how to enable double-click
    > launching of a Java class which has main()
    > method, via Windows filetype association
    > mechanism?
    >
    > If we can't do it, then, why it is?


    Write a script that takes the name of the class file and spawns java
    with appropriate arguments. For example, on Windows XP, I've created an
    "Open" action for the .class file type, defined to run the following
    command:

    C:\ruby\bin\rubyw.exe -w C:\files\ruby\open.rb "%1"

    The ruby script open.rb is something I can also use from the command
    line to open files in my own wily ways. It looks like this:

    begin
    f = ARGV.shift or raise "usage: open <file> [args...]"
    case f
    when /\\([^\\]+)\.class$/
    cmd = "javaw #{$1} #{ARGV}"
    system(cmd)

    # <snip>handling of other file types</>

    else
    raise "unknown file type: #{f}"
    end
    rescue Exception => x
    STDERR.puts x
    end
    Jeffrey Schwab, Jun 4, 2006
    #2
    1. Advertising

  3. "hiwa" <> wrote in message
    news:...
    >I know this really is a Windows issue but
    > I can't find its official documentation nowhere.
    >
    > My question is: how to enable double-click
    > launching of a Java class which has main()
    > method, via Windows filetype association
    > mechanism?
    >
    > If we can't do it, then, why it is?
    >


    Jar file? Will work as long as winrar has not stolen the association.

    --
    LTP

    :)
    Luc The Perverse, Jun 4, 2006
    #3
  4. hiwa

    Dale King Guest

    hiwa wrote:
    > I know this really is a Windows issue but
    > I can't find its official documentation nowhere.
    >
    > My question is: how to enable double-click
    > launching of a Java class which has main()
    > method, via Windows filetype association
    > mechanism?
    >
    > If we can't do it, then, why it is?


    To provide a more thorough answer, what you want is to package up the
    classes correctly into a jar file. With an appropriately set-up
    executable jar file you can double-click it to run it in Windoze.

    For more information see:

    http://www.google.com/search?hl=en&q=executable jar&btnG=Google Search

    --
    Dale King
    Dale King, Jun 4, 2006
    #4
  5. hiwa

    hiwa Guest

    Dale King ã®ãƒ¡ãƒƒã‚»ãƒ¼ã‚¸:

    > hiwa wrote:
    > > I know this really is a Windows issue but
    > > I can't find its official documentation nowhere.
    > >
    > > My question is: how to enable double-click
    > > launching of a Java class which has main()
    > > method, via Windows filetype association
    > > mechanism?
    > >
    > > If we can't do it, then, why it is?

    >
    > To provide a more thorough answer, what you want is to package up the
    > classes correctly into a jar file. With an appropriately set-up
    > executable jar file you can double-click it to run it in Windoze.
    >
    > For more information see:
    >
    > http://www.google.com/search?hl=en&q=executable jar&btnG=Google Search
    >
    > --
    > Dale King

    Thanks. But the topic is not executable jar file.
    I just have a naive question for plain Java class file and Windows
    [open] action association.
    Why we can't associate it with java or javaw command?
    hiwa, Jun 4, 2006
    #5
  6. Hi,

    hiwa wrote:
    >>>I know this really is a Windows issue but
    >>>I can't find its official documentation nowhere.
    >>>
    >>>My question is: how to enable double-click
    >>>launching of a Java class which has main()
    >>>method, via Windows filetype association
    >>>mechanism?
    >>>
    >>>If we can't do it, then, why it is?

    >>
    >>To provide a more thorough answer, what you want is to package up the
    >>classes correctly into a jar file. With an appropriately set-up
    >>executable jar file you can double-click it to run it in Windoze.
    >>
    >>For more information see:
    >>
    >>http://www.google.com/search?hl=en&q=executable jar&btnG=Google Search

    >
    > Thanks. But the topic is not executable jar file.
    > I just have a naive question for plain Java class file and Windows
    > [open] action association.
    > Why we can't associate it with java or javaw command?


    This is because java/javaw wants the class-name without the extension
    ".class" (and with package-information instead of path-information).

    Don't ask me *why* sun did not allow to give the class-filename as
    parameter - I think that it would be a good idea, as well.

    On the other hand - what's the problem to embed the classfile in a
    jarfile? (You can avoid some classpath problems then, e.g....)

    Ciao,
    Ingo
    Ingo R. Homann, Jun 7, 2006
    #6
  7. hiwa

    Dale King Guest

    Ingo R. Homann wrote:
    > Hi,
    >
    > hiwa wrote:
    >>>> I know this really is a Windows issue but
    >>>> I can't find its official documentation nowhere.
    >>>>
    >>>> My question is: how to enable double-click
    >>>> launching of a Java class which has main()
    >>>> method, via Windows filetype association
    >>>> mechanism?
    >>>>
    >>>> If we can't do it, then, why it is?
    >>>
    >>> To provide a more thorough answer, what you want is to package up the
    >>> classes correctly into a jar file. With an appropriately set-up
    >>> executable jar file you can double-click it to run it in Windoze.
    >>>
    >>> For more information see:
    >>>
    >>> http://www.google.com/search?hl=en&q=executable jar&btnG=Google Search

    >>
    >> Thanks. But the topic is not executable jar file.
    >> I just have a naive question for plain Java class file and Windows
    >> [open] action association.
    >> Why we can't associate it with java or javaw command?

    >
    > This is because java/javaw wants the class-name without the extension
    > ".class" (and with package-information instead of path-information).
    >
    > Don't ask me *why* sun did not allow to give the class-filename as
    > parameter - I think that it would be a good idea, as well.


    I can tell you why because a program is not usually a single class file.
    It is a bunch of class files arranged in a tree of packages. You have to
    have some form of class path. Do you expect Java to deduce your class
    path to find the rest of the classes?

    --
    Dale King
    Dale King, Jun 10, 2006
    #7
  8. Hi,

    Dale King wrote:
    >> Don't ask me *why* sun did not allow to give the class-filename as
    >> parameter - I think that it would be a good idea, as well.

    >
    > I can tell you why because a program is not usually a single class file.
    > It is a bunch of class files arranged in a tree of packages. You have to
    > have some form of class path. Do you expect Java to deduce your class
    > path to find the rest of the classes?


    I know. But in many cases, it would be enough, if java would use a
    "default" classpath with the "current" directory (or the directory, in
    which the classfile is placed). Indeed, that would be some kind of
    deduction, but not very tricky:

    Consider, you have some classes: "MainClass" in the default-package and
    "packageA.subpackageX.OtherClass". Then your directories would be:

    /application/bin/MainClass.class
    /application/bin/packageA/subpackageX/OtherClass.class

    Now, if you double-click on MainClass.class, what would be the problem
    to "guess" where OtherClass is placed?

    Two notes:

    (1) I know that I must improve this logic, so that jar-files can be
    found (as usual, "$APP/lib/*.jar")

    (2) As I said: "On the other hand - what's the problem to embed the
    classfile in a jarfile? (You can avoid some classpath problems then,
    e.g....)"

    Ciao,
    Ingo

    PS: Yes, I am aware that the word "subpackage" does not exist in java,
    but I guess you know what I mean by this. :)
    Ingo R. Homann, Jun 12, 2006
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. tshad
    Replies:
    1
    Views:
    372
    Saravana
    Oct 29, 2004
  2. =?Utf-8?B?SmFzb24=?=

    Double Clicking Server Buttons

    =?Utf-8?B?SmFzb24=?=, Jul 22, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    375
    Joerg Jooss
    Jul 23, 2005
  3. Buddy Ackerman

    Disable button to prevent double clicking

    Buddy Ackerman, Feb 27, 2006, in forum: ASP .Net
    Replies:
    10
    Views:
    60,638
  4. Sydex
    Replies:
    12
    Views:
    6,454
    Victor Bazarov
    Feb 17, 2005
  5. Replies:
    3
    Views:
    344
    Andrew Thompson
    Apr 13, 2007
Loading...

Share This Page