• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Registration of Java App with Windows

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
How a java application can be registered with windows. I mean that when I double click a file made with my java app it could be open in it as happens with MS WORD and other softwares.
UMAR ANIS
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The easiest way is to create a app.bat file that contains the commands to invoke the application. The advantage of this is that you can set the classpath to whatever you want on the way in etc.
Then you can either create an icon that invokes the bat file, or let the user doulble click on the bat file.
 
umar pak
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have not understood my question. What I want is that when the files made by my application are double clicked they are open in my application as it happens with other windows applications like when we click a file with .doc extension it opened in MS WORD.
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what is WRONG with double clicking on a MyApp.bat file in explorer instead? That's what the folks at my company do. They don't seem to get confused by it. I can create an icon with it if I want, etc.
What is so all fired special about having the letters exe on the end?
 
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're still missing the point of the question. He is saying that his application creates/uses files with some proprietary extension, say .abc, and wants his application to automatically open whenever someone clicks on the .abc file. You wouldn't want to create a batch file for every .abc file created, right?


I'm pretty sure that this is a platform dependent issue, so the only way to do it would be with native code.
 
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know what you are talking about, this will have to be done though though windows api, because you will have to register you app with windows registry, it's some work to be done on your part , if you want i might be able to look up some of the api calls that must be made.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmmm... I bet that there's a way to do it... you can do it "by hand" by going into File Explorer, doing a View|Options|FileTypes... and associating a file type with the command line ( i.e. javaw YourClass ) that you want to run... the only problem is doing it automatically with an "installer" of some sort. I think some of the commercially available installers wouldn't have a problem with this, since they can set registry values as well as uncompress and copy files. However, to do this in Java all you would have to do is to find a way to write to the windows registry... I'm sure that I've heard of someone using JNI or something to do this...

There probably are other implementations out there, but the first one I found doing a search on "Java windows registry" was a class called JREG.

There is not really a problem with your main program being platform independent if you do this... just your "installer" program that registers everything will be platform dependent, and windows users would get a little bit extra...

HTH,
-Nate
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, I really DID mis-read this question. Sorry. And I am not sure of the answer either.
Yes, you can set the registry by hand (Explorer/View/Options/File Types) and set a program just like you set .txt to fire up C:\WINDOWS\NOTEPAD.EXE. You can set up your extension to fire up with application c:\jdk1.3.0\bin\myApp.bat
I know that URLConnection and some other classes like JEditorPane have a method setContentType("html/MS-Excel");
And there is a ContentHandlerFactory that URLConnection uses. But I have not used them.
 
umar pak
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can do it in Visual C++, to do it in java, will I have to use JNI. I haven't used it yet so if it can solve my problem, give me some links and also a brief introduction of it.
Thank you
UMAR ANIS
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A JNI tutorial:
http://java.sun.com/docs/books/tutorial/native1.1/concepts/index.html
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone write about coding a bat file? (especially you cindy.. you look knowing it..)
i want to run c:\dir1\Appl.class with a bat file.. let the classpath be c:\dir2.. please write all the code of the bat file.. thanx.. (i was also feeling silly cindy..)
 
Cindy Glass
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a DOS machine,
(Well it would probable go in c:\"Program Files"\dir instead of c:\dir, but You can change that later)
For a simple case where there is no jar file no other jar files to consider (and the jdk is in c:\dir\jre\bin - but you can change that) you have 3 commands. 1 Get to the correct directory. 2 - Set the path. 3 Call java (or javaw) with a classpath parameter (most likely) and name the class to execute.
In file Appl.bat you put:
cd \dir
path = .;C:\dir;C:\dir\jre\bin;
"c:\dir\jre\bin\javaw" -classpath .;"c:\dir" Appl

For a complicated example that has the runtime stuff embedded in the HUGE classpath statement, and is expecting a properties file in- something like this (still 3 commands):
cd \dir
path = .;C:\dir;C:\dir\jre\bin;
"c:\dir\jre\bin\javaw" -classpath .;"c:\dir";"c:\dir\Appl.jar";"c:\dir\deploy.jar";"c:\dir\jre\lib\rt.jar";"c:\dir\jre\lib\jaws.jar";"c:\dir\jre\lib\i18n.jar";"c:\dir\classes12.jar";"c:\dir\images" Appl.someSubDirectory.Appl "c:\dir\APPl.properties"
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have another query regarding this,
1. I have an application that runs on the browser I did the same thing as Cindy has mentioned but basically wat I have created is an shortcut of my browser. Is there anyway I can set the URL.
please help soon...
 
reply
    Bookmark Topic Watch Topic
  • New Topic