Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / June 2006

Tip: Looking for answers? Try searching our database.

Double-clicking Java class file on Windows

Thread view: 
hiwa - 03 Jun 2006 23:41 GMT
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?
Jeffrey Schwab - 04 Jun 2006 00:37 GMT
> I know this really is a Windows issue but
> I can't find its official documentation nowhere.
[quoted text clipped - 5 lines]
>
> 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
Luc The Perverse - 04 Jun 2006 01:17 GMT
>I know this really is a Windows issue but
> I can't find its official documentation nowhere.
[quoted text clipped - 5 lines]
>
> If we can't do it, then, why it is?

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

--
LTP

:)
Dale King - 04 Jun 2006 04:10 GMT
> I know this really is a Windows issue but
> I can't find its official documentation nowhere.
[quoted text clipped - 5 lines]
>
> 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

Signature

 Dale King

hiwa - 04 Jun 2006 10:15 GMT
Dale King :

> > I know this really is a Windows issue but
> > I can't find its official documentation nowhere.
[quoted text clipped - 16 lines]
> --
>   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?
Ingo R. Homann - 07 Jun 2006 13:30 GMT
Hi,

>>>I know this really is a Windows issue but
>>>I can't find its official documentation nowhere.
[quoted text clipped - 18 lines]
> [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
Dale King - 10 Jun 2006 04:35 GMT
> Hi,
>
[quoted text clipped - 26 lines]
> 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?

Signature

 Dale King

Ingo R. Homann - 12 Jun 2006 10:26 GMT
Hi,

>> 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.
[quoted text clipped - 3 lines]
> 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. :-)


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.