Sign in to follow this  

[java] executing external programs from java

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I don't know if I have an answer for that, but what would the URL look like? Say, a .jar on the end? Is this supposed to be from within a Java application? Or just in response to some arbitrary URL?

L-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You may want to look into java web start application.
I havent used it, but from what I understand, it starts a java app when you go to a web page. Of course there is much more to this...but I think that is waht you want

Share this post


Link to post
Share on other sites
Okay then you'll want to have a look at this link:

When Runtime.exec() Won't

This will show you how to do a runtime call to an exe. Which in the case of IE should also accept a command line URL, and it does. On another OS, I'm sure it will work similarly (haven't tried it on a Unix box)... but generally something like this is about 100 times easier on a Unix box.

L-

Share this post


Link to post
Share on other sites
Quote:
Original post by Lucidquiet
Okay then you'll want to have a look at this link:

When Runtime.exec() Won't

This will show you how to do a runtime call to an exe. Which in the case of IE should also accept a command line URL, and it does. On another OS, I'm sure it will work similarly (haven't tried it on a Unix box)... but generally something like this is about 100 times easier on a Unix box.

L-


This should be what I need. Tomorrow I will try it. By the way, is there a way to detect which is the default browser? This is not so important, but would be nice...
Thank you again!

EDIT: I tried to rate you up but it doesn't work. Am I restricted to only one time? That's the first time that this happens to me, so I don't know...

Share this post


Link to post
Share on other sites
Quote:
Original post by cignox1
EDIT: I tried to rate you up but it doesn't work. Am I restricted to only one time? That's the first time that this happens to me, so I don't know...


I don't know about that either -- but thanks nonetheless. :)

L-

Share this post


Link to post
Share on other sites
Well as said above you could use something like
Runtime.getRuntime().exec("iexplore www.website.com") but it has a lot of problems :
-you must detect the operating system and use a particular command depending on each os.
-Will your aplication still work with a newer version of windows/linux?
-What will happen with an exotic os (solaris/freebsd/...)?
-What if the command is not supported anymore later?
-In the windows case you can launch internet explorer but you can't launch (easaliy) the default browser.
-...

Fortunately there is a really nice java library which solve the problem: JDIC (Desktop Integration for Java Applications).
It's aim is to allow a better integration of java application with the operating system.
Here is the link : https://jdic.dev.java.net/
Another link since the above link seems to have problems at the moment http://javadesktop.org/articles/jdic/index.html

with jdic you can :
-Launch the system default browser
-embed a web browser INSIDE your application
-Launch the application associated with a given File
-Launch the default system mailing system such as outlook (think mailto:me@blah.com)
-Put your application in the system tray
And a lot of other nifty things.

Share this post


Link to post
Share on other sites
Some of these features are coming along with Mustang. Although it's not stable enough to produce software over it, you can plan a release on it depending on the time you have to deliver such code. But there's nothing wrong, and it might still be the safest approach, to use JDK 1.5 + JDIC.

Son of Cain

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
i haven't used JDIC yet, but it sounds like it would be the way to go.

my (quite hackish) solution to the "launching the default app for something" problem (which only works under windows, but that didn't matter in the project i was using it) was the following (i used it for launching acroread for viewing a PDF, but it should be usable for things like the default browser also):


/**
* Starts the default viewer, thats linked to the filetype
* of the file <code>f</code>.
* @param f The file to be opened.
*/

public static void spawnFileProg(File f) {
if (f.exists() && f.isFile() && f.canRead()) {
// comspec is the name of the command line interpreter, you should
// really get it with something like:
//String comspec = System.getenv("COMSPEC");
// ...

String comspec = "cmd";

try {
Runtime.getRuntime().exec(
comspec + " &#47;c start \"Please wait...\" " + f.getName(),
null,
f.getParentFile());
} catch (IOException e) {
throw new RuntimeException(
"Couldn't start the viewer for: " + f,
e);
}
} else {
// File doesn't exist or isn't readable, do something about it!
// ...
}
}



This uses the nifty "start" command that's present in most modern windows-cli's.

-Raven

Share this post


Link to post
Share on other sites
Thank you all! The current project is targeted on a very limited platforms set: my girlfriend pc :-)
I developed it to be more general than I actually needed (good for experience) but I don't feel like using another api just to start the default browser (that feature is one of the less influent in the app, I added it only because I thought it would have been cool, but most probably she will never use it) so I think I will simply run iexplorer.
Thank you anyway!

Share this post


Link to post
Share on other sites

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this