Meaningless Drivel is fun!*
The moose likes Java in General and the fly likes Registration of Java App with Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Registration of Java App with Windows" Watch "Registration of Java App with Windows" New topic
Author

Registration of Java App with Windows

umar pak
Greenhorn

Joined: Jan 05, 2001
Posts: 20
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
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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.


"JavaRanch, where the deer and the Certified play" - David O'Meara
umar pak
Greenhorn

Joined: Jan 05, 2001
Posts: 20
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"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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?
Angela Lamb
Ranch Hand

Joined: Feb 22, 2001
Posts: 156
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.
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
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.


Val SCJP <BR>going for SCJD
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

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


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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

Joined: Jan 05, 2001
Posts: 20
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"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
A JNI tutorial:
http://java.sun.com/docs/books/tutorial/native1.1/concepts/index.html
myJava forumName
Greenhorn

Joined: Jun 04, 2001
Posts: 7
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"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
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"
Subramaniam Krishnan
Greenhorn

Joined: Jun 04, 2001
Posts: 10
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...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Registration of Java App with Windows
 
Similar Threads
Calling vb component resides on windows from java on unix
is there an API for Java control of Windows Services?
Sun Java System Application Server 8 as a Windows service?
Java driver on top of a Windows application?
Read values from Registry