Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Double-clicking Java class file on Windows

Reply
Thread Tools

Double-clicking Java class file on Windows

 
 
hiwa
Guest
Posts: n/a
 
      06-03-2006
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?

 
Reply With Quote
 
 
 
 
Jeffrey Schwab
Guest
Posts: n/a
 
      06-03-2006
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
 
Reply With Quote
 
 
 
 
Luc The Perverse
Guest
Posts: n/a
 
      06-04-2006
"hiwa" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) oups.com...
>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




 
Reply With Quote
 
Dale King
Guest
Posts: n/a
 
      06-04-2006
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...=Google+Search

--
Dale King
 
Reply With Quote
 
hiwa
Guest
Posts: n/a
 
      06-04-2006
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...=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?

 
Reply With Quote
 
Ingo R. Homann
Guest
Posts: n/a
 
      06-07-2006
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...=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

 
Reply With Quote
 
Dale King
Guest
Posts: n/a
 
      06-10-2006
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...=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
 
Reply With Quote
 
Ingo R. Homann
Guest
Posts: n/a
 
      06-12-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ class to parse java .class file wolverine C++ 2 03-26-2007 03:36 PM
Class A contains class B, class B points to class A Joseph Turian C++ 5 12-30-2005 03:24 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
A parameterized class (i.e. template class / class template) is not a class? christopher diggins C++ 16 05-04-2005 12:26 AM
instanciate a class in a jar file with class.forname, while my main class is in another jar cyril Java 2 08-25-2004 06:55 AM



Advertisments